react通过函数调用实现子传父

每次调用该方法都会提示
index.js:1 Warning: Cannot update a component (Index) while rendering a different component (Addpro). To locate the bad setState() call inside Addpro
请问各路大神 这个问题如何解决
父组件
image.png
子组件
image.png

阅读 8.1k
2 个回答

把props.changeVisible这句移到该去的钩子里,直接在函数组件顶层调这种会改变状态的功能显然不太合适

props.changeVisible(visible)
放到useEffeact里面去??

看起子组件渲染时 调用父组件方法 又触发重新渲染了

推荐问题