I
I
IvanIvanIvanIvanIvan2018-04-25 14:51:04
React
IvanIvanIvanIvanIvan, 2018-04-25 14:51:04

How to pass an argument to a handler?

There is a method

modalRun = (state) => {
    this.setState((prevState, state) => {
      return {
          modal: {
            ...prevState.modal,
            state: state
        }
      };
    });  
  };

There are processors
<Button 
                               
   onPress={() => this.modalRun(1)}
   >

It transmits by clicking on 1, and some unknown object. Is it possible to pass 1?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-04-25
@IvanIvanIvanIvanIvan

First, the state parameter of the function passed to setState overrides the state parameter passed to modalRun. Secondly, the second parameter of the function passed to setState is props, not state at all. In general, fool yourself with a stupid choice of parameter names. Do something like this:

modalRun = (modalState) => {
  this.setState((prevState, props) => {
    return {
      modal: {
        ...prevState.modal,
        state: modalState
      }
    };
  });  
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question