将子组件作为父组件中的道具发送并在父方法中将道具添加到子组件

时间:2021-03-24 20:19:39

标签: javascript reactjs

嗨,我正在尝试在我的父组件中添加一个组件作为道具,然后从父方法向子组件添加道具,例如:

function Parent(props) {
   const ParentChild = props.child;
   return ( 
      <ParentChild someprop=1 />
   )
}

function Child(props) {
    return <span>{props.someprop}</span>
}

当我创建父母时:

<Parent child={Child} />

这似乎不起作用我该怎么做?我正在使用 React 和 TypeScript

0 个答案:

没有答案