问题
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