Skip to content
Advertisement

change parent state from child

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} />
) }
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement