Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to use `setState` callback on react hooks

//You need to use useEffect hook to achieve this.

const [counter, setCounter] = useState(0);

const doSomething = () => {
  setCounter(123);
}

useEffect(() => {
   console.log('Do something after counter has changed', counter);
}, [counter]);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #How #callback #react #hooks
ADD COMMENT
Topic
Name
4+7 =