I want to use const inside if(conditional branch), but I couldn't set const in if.
Is there a way to use const or set a variable in a conditional branch? Or are there any problems of my code?
Could you give some advice please?
export default class ApplauseButton extends Component {
constructor(props) {
super(props);
this.state = {
count: 0,
applause: 100,
applauded: 0,
};
}
handlClick= async ()=> {
const {
mainuser,
subuser,
} = this.props;
if (mainuser === 'User1'){
const countapplauded = this.state.applauded + 1;
} else if (mainuser === 'User2') {
const countapplauded1 = this.state.applauded1 + 1;
}
};
render() {
const {
mainuser,
subuser,
} = this.props;
return (
<View style={styles.container}>
<TouchableHighlight
onPress={() => {this.handlClick()}}
onLongPress={this._onLongPressButton} underlayColor="white">
<View style={styles.button}>
<Text style={styles.buttonText}></Text>
</View>
</TouchableHighlight>
</View>
);
}
}