score:4

Two things you should avoid when using state:

  1. Do not mutate objects in the current state. Always create new objects to update the state. You can use the spread operator for that.

  2. Calls to setState are asynchronous - don’t rely on this.state to reflect the new value immediately after calling setState. Use the callback version of setState() instead. React batches updates and when the update happens this.state does not contain the data from previously scheduled updates and may override them.

Example:

addAnother(){
    this.setState(oldState => ({
        formList: [...oldState.formList, formModel]
    }));
}

Related Query

More Query from same tag