I want to change the parent state from the child
export const ParentComponent=()=>{ const [ resendCodeStatus ,setResendCodeStatus ] = useState(false) const callback=()=>{ setResendCodeStatus(!resendCodeStatus) } return ( < Timer callback={callback} /> ) }
but I can access the callback function just once
Advertisement
Answer
Try this:
export const ParentComponent=()=>{ const [ resendCodeStatus ,setResendCodeStatus ] = useState(false) const callbackFunction=()=>{ setResendCodeStatus((status) => !status) } return ( <Timer callbackFunction={callbackFunction} /> ) }