【发布时间】:2016-10-17 20:37:31
【问题描述】:
好的,我正在尝试将我用作参数的对象内的组件传递给我正在触发的操作。
this.context.alt.actions.notificationActions.logMessage({
component: <ModalLayoutEditorComments subscription="pop-up" contextualClass="info" callback={this._submitCaisseChangeAction} />,
subscription: 'pop-up',
});
在目标组件中,我将对象作为道具接收到现在是 React Element 的组件。
现在我想知道如果可能的话,如何在另一个 React 组件中转换这个 React 元素?
render() {
const Component = this.props.notifications[0].component;
return (
<div>
{Component}
</div>
);
}
【问题讨论】:
-
您的
render方法看起来不错 - 这是渲染作为道具传递的元素的示例:jsfiddle.net/txqo702m/1 -
在另一个 React 组件中使用 ReactDOM.render 可以吗?我尝试使用 React.cloneElement 没有运气。
-
你不是在组件内调用
ReactDOM.render吗?组件render方法构建了一个 React 元素树,最终由应用根目录下的ReactDOM.render转换为 DOM 元素树。
标签: javascript reactjs components