0
我想创建一个简单的应该尽可能通用的Wizard
组件。React中的动态模板
我想为身体内容注入2个参数:template
(包括一些逻辑)及其context
。
export class ParentClass extends React.Component {
render() {
let template = `Some text: {this.context.testFunc()}`;
let context = new TestContext();
return (
<Wizard template={template} context={context} />
);
}
}
export class TestContext {
testFunc() {
return "another text";
}
}
export class Wizard extends React.Component {
context: null;
constructor(props) {
super(props);
this.context = this.props.context;
}
render() {
return (
<div>
{this.props.template}
</div>
);
}
}
的问题是包含在template
不执行(它在Wizard
写入一切作为字符串)的逻辑。
我使用ES2015
和Babel
进行编译。