【发布时间】:2021-04-03 09:09:55
【问题描述】:
我有一个动态构造道具的要求,有点困惑来构造它。看下面的例子,子表达式组件在这种情况下需要父组件标题。
function SomeComponent(props){
return <h1>{props.title}</h1>
}
import SomeComponent from 'someForm';
const contents = {
title: 'hello',
form: SomeComponent
}
另一个组件:
<Another data={contents}>
function Another(props){
return (
<Form title={props.data.title}>
{props.data.form} => title should be passed to this component expression
something like: <props.data.form title={props.data.title}>
Is it possible or how to do this?
</Form>
);
}
实现这一目标的最佳方法是什么? HOC 是一个选项,但问题到底是什么?
【问题讨论】:
标签: reactjs higher-order-components