E
E
Evgeny Kucherenko2017-01-31 21:57:29
React
Evgeny Kucherenko, 2017-01-31 21:57:29

Function instead of object in setState?

I came across an article on React, which describes the benefits of changing state with a function call.
There is a structure like this:

submit(){
   this.setState(function(prevState, props){
      return {showForm: !prevState.showForm}
   });
}

Please explain, what is the use of the props parameter, which is not used? I'm more of a mathematician than a proger, I don't understand such jokes

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Bobylev, 2017-01-31
@evgenyspace

The presence of a function argument does not force it to be used. This is done so that, if desired, you can refer to the properties.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question