?
, submit.
. , React state . ( handleInputChange
), React (, , ), .
, React , . :
Form updated -> handleInputChange -> state updated -> updated state passed to other components accessing it
, <Card />
, <Form />
, , - , , , , . , <Card />
, <Form />
.
, React , , . . " " , . , , , .
setState
React docs:
setState()
.
this.props
this.state
, .
, , , this.state
. , ; , ( , ), React docs ( ), function
, object
:
this.setState((prevState, props) => ({
counter: prevState.counter + props.increment
}));
If you are still wondering when you can use the method safely setState
, use it if other components do not rely on state or when you do not need to save state (save to local storage or to the server). When working with larger projects, it is always recommended to use state containers to save yourself the hassle, such as Redux .