I'm trying to use callback of setState() in order to check that the state was changed correctly. However, I get an error Expected 1 arguments, but got 2.
setCurrentLength(300, () => {
console.log('Current length ', currentLength);
});
How to solve it? Thanks
You are using the callback for setState. But you are using useState hook.
Use should use useEffect for this with dependency array, so when ever currentLength is changed your console.log will be executed.
useEffect(()=>{
console.log('Current length ', currentLength);
}, [currentLength]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With