【发布时间】:2023-03-24 17:30:02
【问题描述】:
我正在尝试使用 {children} 将道具传递给子组件。
父亲组件:
const FatherComp = ({ children, propsToPassToChild }) => (
<div>Dynamic component content:
{children}
</div>
)
子组件:
const ChildComp = ({ childProps }) => <p>This is the dynamic content</p>
像这样使用它们:
<FatherComp>
<ChildComp/> // childProps cannot be passed here since it's inside FatherComp
</FatherComp>
我想将来自 FatherComp 的道具 (propsToPassToChild) 直接传递给 ChildComp:
const FatherComp = ({ children, propsToPassToChild }) => (
<div>Dynamic component content:
>>>>> {children} <<<<< *passing the props somewhere here*
</div>
)
是否有可能通过直接反应功能组件而无需状态管理来实现我想要做的事情?
谢谢!
【问题讨论】:
标签: javascript reactjs next.js react-props react-functional-component