search

Home  >  Q&A  >  body text

javascript - The onPress function in react-native cannot directly write functions with parameters

 <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?

天蓬老师天蓬老师2807 days ago940

reply all(1)I'll reply

  • 仅有的幸福

    仅有的幸福2017-06-10 09:51:13

    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.

    reply
    0
  • Cancelreply