Answers for "react state not updating immediately"

1

react state not updating immediately

//In case of hooks, you should use useEffect hook.
const [fruit, setFruit] = useState('');

setFruit('Apple');

useEffect(() => {
  console.log('Fruit', fruit);
}, [fruit])
Posted by: Guest on June-10-2021
0

setstate not updating state immediately

this.setState({pencil:!this.state.pencil}, myFunction)
Posted by: Guest on December-04-2020
0

setstate not updating state immediately

myFunction = () => {
  this.props.updateItem(this.state)
}
Posted by: Guest on December-04-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language