I am trying to update the state with a localStorage value in DidMount, but it is not updating:
type Props = { }; type State = { id_evaluation: string, }; c
setState works asynchronously so pass console.log as callback to get updated state.
setState
console.log
callback
this.setState({ id_evaluation: '1'}, () => console.log('2- ', this.state.id_evaluation));
when used as your code, console.log('2 - ', this.state.id_evaluation) is printing previous state not the updated state.
console.log('2 - ', this.state.id_evaluation)