I am trying to update the react state and then immediately add the new state to local storage as below
constructor(props) {
super(props);
this.state = {
testState: "testValue"
};
}
testFunction = (test) => {
this.setState({ testState: [...this.state.testState, test] });
localStorage.setItem("dummy", this.state.testState.toString());
}
However, the state change is not reflecting when I call the local storage method.
As a result i am ending up storing old value in the local storage.
But when testFunction execution completes, the component is reloaded with the updated state.
Thanks in advance!