Two function in a event on React-Native

半世苍凉 提交于 2019-12-12 02:59:15

问题


How to put two function in a event like onValueChange?

I tried with

  onValueChange={(selected) => this.setState({selected}),this.state.eventOnChange}>

回答1:


What about:

onValueChange={(selected) => { 
    this.setState({selected});
    this.state.eventOnChange();
}}



回答2:


Component.setState() is asynchronous and may be locked on the second call while it is still doing the first.

Do the second call in a callback like this:

onValueChange=
    { (selected) => {
        this.setState(
            {category:selected},() => {this.filter();} // Add Functions That's you want to call.
        )
    }
}



回答3:


Resolved with the following code:

<TextInput
      style={{height: 40, width: 200, borderColor: 'gray', borderWidth: 1, }}

      onChangeText={(text) => this.setState({
        text
      }, () => {
        this._onChangeText();
      })
      } 
      autoCorrect={false}
      underlineColorAndroid='rgba(0,0,0,0)'
      value={this.state.text}
    />

Thanks to @pinewood.



来源:https://stackoverflow.com/questions/36161344/two-function-in-a-event-on-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!