首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改父状态从子状态

更改父状态从子状态
EN

Stack Overflow用户
提问于 2021-01-15 10:05:36
回答 1查看 35关注 0票数 0

我想将父状态从子状态更改为

代码语言:javascript
复制
export const ParentComponent=()=>{

 const [ resendCodeStatus ,setResendCodeStatus ] = useState(false)

 const callback=()=>{

   setResendCodeStatus(!resendCodeStatus)

 }

 return (

   < Timer  callback={callback} />

 )
}

但是我只能访问回调函数一次。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-15 10:17:31

试试这个:

代码语言:javascript
复制
export const ParentComponent=()=>{

const [ resendCodeStatus ,setResendCodeStatus ] = useState(false)
const callbackFunction=()=>{
setResendCodeStatus((status) => !status)
}
return (
<Timer callbackFunction={callbackFunction} />
) }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65734072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档