Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

state hook is not updating react

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: #state #hook #updating #react
ADD COMMENT
Topic
Name
6+2 =