4Manuals

  • PDF Cloud HOME

您可以在JSX中创建来自组件的传递组件的react组件吗? Download

    反应:更改方向后触发重新渲染和offsetWidth的重新计算 如何在react图表上的datakey中操作DateTime 如何在nextjs中使用html2canvas 使用一些Typescript文件测试React应用 React-native动画时间序列及其百分比或替代 谁能帮助我通过wordpress登录和注册来创建React Native应用? 如何检查电子屏幕截图的允许状态(macOS catalina) 如何在reactjs中更新值 时间戳格式不支持将React`react-datepicker`作为默认值 我正在尝试将nextjs应用程序构建到静态html页面中,我有一些错误

我有一些渲染相同组件的路由。每条路线都有一个特定的组件作为其要呈现的属性。

<CommonComponent specificComponent={SpecificComponent} propName="propValue" />

这在CommonComponent中可以正常工作:

React.createElement(specificComponent, { dataUrl: dataUrl });

是否有JSX方式来做React.createElement?路由示例如下:

<Route path="/pageOne">
    <CommonComponent specificComponent={SpecificComponentOne} dataUrl="dataUrl" />
</Route>
<Route path="/pageTwo">
    <CommonComponent specificComponent={SpecificComponentTwo} dataUrl="dataUrl" />
</Route>

1 个答案:

答案 0 :(得分:1)

是的,有。所需的技巧是将组件存储在具有大写名称的变量中!听起来很傻,但这是事实。因此,在CommonComponent中,您可以使用:

const ComponentToRender = props.specificComponent;
return (<ComponentToRender ... />);



Similar searches
    用户名表单登录连接到主页 如何使用SQL将百分比添加到表中? 是否可以检查GNU sed中的反向引用是否为空? 保存在react-admin 谁能用子查询和CTE回答SQL问题?