javascript - The onPress function in react-native cannot directly write functions with parameters
天蓬老师
天蓬老师 2017-06-10 09:49:13
0
1
892
 <Icon.Button onPress={() => {this._change('male')}} name="ios-male">男</Icon.Button>

Writing like this will report an error. You need to write it in the following way and put it in return

  <Icon.Button onPress={() => {() => {this._change('male')} }} name="ios-male">男</Icon.Button>

Does anyone know why?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
仅有的幸福

This is not a function with parameters. You are directly executing a function with parameters.
Didn’t you realize that _change is executed without waiting for the click to start?

The second way to write it is to wrap this method with a function, and execute this function when clicked.

Let’s take a look at the relevant basics.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template