[英]Render a React element inside a React component
確定,我正在嘗試將用作參數的對象內的組件傳遞給我觸發的動作。
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
邏輯還可以。 看來您使用的是錯誤的道具:
render() {
return (
<div>
{this.props.notifications[0].component}
</div>
);
}
順便說一句, component
是一個非常令人困惑的屬性名稱。 該對象是一個React元素,它是Component實例的描述 。
我得到的錯誤是以下
元素類型無效:需要一個字符串(對於內置組件)或一個類/函數(對於復合組件),但得到:未定義
我變得不確定,因為我犯的錯誤是我沒有使用export default ModalLayoutEditorComments
導出組件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.