Javascript 在React组件内渲染React元素
好的,我正在尝试将对象中的一个组件作为参数传递给我正在触发的动作Javascript 在React组件内渲染React元素,javascript,reactjs,components,Javascript,Reactjs,Components,好的,我正在尝试将对象中的一个组件作为参数传递给我正在触发的动作 this.context.alt.actions.notificationActions.logMessage({ component: <ModalLayoutEditorComments subscription="pop-up" contextualClass="info" callback={this._submitCaisseChangeAction} />, subscription: 'pop-u
this.context.alt.actions.notificationActions.logMessage({
component: <ModalLayoutEditorComments subscription="pop-up" contextualClass="info" callback={this._submitCaisseChangeAction} />,
subscription: 'pop-up',
});
this.context.alt.actions.notificationActions.logMessage({
组成部分:,
订阅:'弹出',
});
在目标组件内部,我接收对象作为道具,该组件现在是React元素
现在我想知道,如果可能的话,如何在另一个React组件中转换这个React元素
render() {
const Component = this.props.notifications[0].component;
return (
<div>
{Component}
</div>
);
}
render(){
const Component=this.props.notifications[0]。组件;
返回(
{Component}
);
}
您的渲染逻辑正常。看起来您使用了错误的道具:
render() {
return (
<div>
{this.props.notifications[0].component}
</div>
);
}
render(){
返回(
{this.props.notifications[0].component}
);
}
顺便说一句,组件
是一个相当混乱的属性名称。对象是一个React元素,它是一个。您的渲染逻辑正常。看起来您使用了错误的道具:
render() {
return (
<div>
{this.props.notifications[0].component}
</div>
);
}
render(){
返回(
{this.props.notifications[0].component}
);
}
顺便说一句,组件
是一个相当混乱的属性名称。对象是一个React元素,它是一个。我得到的错误如下
元素类型无效:应为字符串(对于内置组件)
或类/函数(用于复合组件),但得到:未定义
我没有定义,因为我犯的错误是没有使用export default ModalLayoutEditorComments
导出组件。我得到的错误如下
元素类型无效:应为字符串(对于内置组件)
或类/函数(用于复合组件),但得到:未定义
我没有定义,因为我犯的错误是我没有使用export default ModalLayoutEditorComments
导出组件。您的render
方法看起来很好-下面是一个渲染作为道具传递的元素的示例:在另一个React组件中使用ReactDOM.render可以吗?我尝试使用React.cloneElement时运气不佳。您不是在组件内调用ReactDOM.render
?组件render
方法构建一个React元素树,它最终由ReactDOM.render
在应用程序的根目录下变成一个DOM元素树。你的render
方法看起来不错-下面是一个渲染作为道具传递的元素的示例:在另一个React组件中使用ReactDOM.render可以吗?我尝试使用React.cloneElement时运气不佳。您不是在组件内调用ReactDOM.render
?组件render
方法构建一个React元素树,它最终由ReactDOM.render在应用程序的根目录下变成一个DOM元素树。你需要更具体一些吗?错误是什么?呈现作为道具传递的元素是一种常见的反应模式(例如,{children}
)。对你有用吗?很抱歉,延迟是因为我没有定义,所以我犯的错误是我没有使用export default ModallYoutEditorComments导出组件。你需要更具体一些吗?错误是什么?呈现作为道具传递的元素是一种常见的反应模式(例如,{children}
)。对你有用吗?很抱歉,延迟是因为我没有定义,所以我犯的错误是我没有使用export default ModallYoutEditorComments导出组件。