Answer the question
In order to leave comments, you need to log in
How to pass an argument to a handler?
There is a method
modalRun = (state) => {
this.setState((prevState, state) => {
return {
modal: {
...prevState.modal,
state: state
}
};
});
};
<Button
onPress={() => this.modalRun(1)}
>
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question