How to get the value of state after using setState in React

this.setState({ name: "Hello Chris1993!" }, () => {
  console.log(this.state.name); // output: Hello Chris1993!
});


For Functional Component Use useEffect.

useEffect(() => {
  console.log(state) // do something after state has updated 
}, [state]) 

No comments:

Post a Comment