Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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])
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #react #state #updating #immediately
ADD COMMENT
Topic
Name
2+7 =