Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6213

First onchange checkbox execution doesn't run correctly function React Native Help pls

$
0
0

In my first execute my function doens't work.I need a checkbox that adds or subtracts numbers. but it doesn't work on the first run, only on the next ones. console.log () works, but it only adds or subtracts in the second run onwards.

  constructor(props) {    super(props);    this.state = {      valOp1: false,      cotacao: 0.0,      cont: 1,    };  }  op1 = value => {{    this.setState({ valOp1: !this.state.valOp1});     if(this.state.valOp1 == true){      console.log('selected');      this.setState({ cotacao: this.state.cotacao + 10});      console.log(this.state.cotacao);    }    else if(this.state.valOp1 == false){      console.log('not selected');      this.setState({ cotacao: this.state.cotacao - 10});      console.log(this.state.cotacao);    }    }  this.funcop1();}  funcop1(){  }  render(){    return(<View><TextInput    label="Valor Fipe"    value={this.state.val}    maxLength={11}    keyboardType="numeric"    onChangeText= {(val) => this.setState({val})}    /><View style={styles.container}><Text style={styles.checkTitle}>Opcionais:</Text><View style={styles.checkboxContainer}><CheckBox         value={!!this.state.valOp1}         onValueChange={this.op1}         style={styles.checkbox}        /><Text style={styles.label}>Do you like React Native?</Text></View></View></View>    );  }}```

Viewing all articles
Browse latest Browse all 6213

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>