前提・実現したいこと
React Nativeの条件分岐if文の中でconstを使いたいと考えています。
発生している問題・エラーメッセージ
ですが、現状if文の中ではconstにより変数の定義がされていません。
if文内で定数を定義することは可能なのでしょうか?
よろしくお願いします。
該当のソースコード
JS
1export default class ApplauseButton extends Component { 2 3 constructor(props) { 4 super(props); 5 this.state = { 6 count: 0, 7 applause: 100, 8 applauded: 0, 9 }; 10 } 11 12 handlClick= async ()=> { 13 const { 14 mainuser, 15 subuser, 16 } = this.props; 17 18 if (mainuser === 'User1'){ 19 const countapplauded = this.state.applauded + 1; 20 } else if (mainuser === 'User2') { 21 const countapplauded1 = this.state.applauded1 + 1; 22 } 23 }; 24 25 render() { 26 const { 27 mainuser, 28 subuser, 29 } = this.props; 30 31 return ( 32 <View style={styles.container}> 33 <TouchableHighlight 34 onPress={() => {this.handlClick()}} 35 onLongPress={this._onLongPressButton} underlayColor="white"> 36 <View style={styles.button}> 37 <Text style={styles.buttonText}>????</Text> 38 </View> 39 </TouchableHighlight> 40 </View> 41 ); 42 } 43}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/14 23:57