繁体   English   中英

从孩子更改父 state

[英]change parent state from child

我想从孩子改变父母 state

export const ParentComponent=()=>{

 const [ resendCodeStatus ,setResendCodeStatus ] = useState(false)

 const callback=()=>{

   setResendCodeStatus(!resendCodeStatus)

 }

 return (

   < Timer  callback={callback} />

 )
}

但我只能访问一次回调 function

尝试这个:

export const ParentComponent=()=>{

const [ resendCodeStatus ,setResendCodeStatus ] = useState(false)
const callbackFunction=()=>{
setResendCodeStatus((status) => !status)
}
return (
<Timer callbackFunction={callbackFunction} />
) }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM