react callback set staet
setState( { name: "Michael" }, () => console.log(this.state));// => { name: "Michael" }
react callback set staet
setState( { name: "Michael" }, () => console.log(this.state));// => { name: "Michael" }
react functional components setstate callback
const [state, setState] = useState({ name: "Michael" })
const isFirstRender = useRef(true)
useEffect(() => {
if (!isFirstRender.current) {
console.log(state) // do something after state has updated
}
}, [state])
useEffect(() => {
isFirstRender.current = false // toggle flag after first render/mounting
}, [])
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us