好的我試圖傳遞一個組件作爲參數傳遞給我觸發的動作。在React組件內渲染一個React元素
this.context.alt.actions.notificationActions.logMessage({
component: <ModalLayoutEditorComments subscription="pop-up" contextualClass="info" callback={this._submitCaisseChangeAction} />,
subscription: 'pop-up',
});
在目標組件中,我接收對象作爲具有現在是React Element的組件的道具。
現在我想知道我怎麼可以把這個陣營內的另一個元素如果可能的話作出反應成分?
render() {
const Component = this.props.notifications[0].component;
return (
<div>
{Component}
</div>
);
}
你的'render'方法看起來不錯 - 這裏是渲染一個作爲道具傳遞的元素的示例:https://jsfiddle.net/txqo702m/1/ – joews
在另一個React組件內使用ReactDOM.render是好的嗎?我嘗試使用React.cloneElement,但沒有運氣。 – Gab
你不是在組件內調用'ReactDOM.render'?組件'render'方法構建一個React元素樹,最終通過應用程序根部的'ReactDOM.render'變成DOM元素樹。 – joews