ruby-on-rails - 如何使用 react_rails 将子项传递给苗条模板中的组件
问题描述
我正在使用react_rails在 Ruby on Rails 应用程序中的超薄模板内呈现反应组件。有没有办法将子级传递给 React 组件,其中子级在服务器端呈现苗条?
这是我理想中想要的:
<MyComponent>
<p>my custom content</p>
</MyComponent>
内容来自模板本身,如下所示:
= react_component 'MyComponent' do
p my custom content
这可能吗?如果是这样,将孩子传递给 react_component 的最佳方法是什么?
解决方案
在页面加载时,react_ujs 驱动程序将扫描页面并使用 data-react-class 和 data-react-props 安装组件。
视图助手的签名是:
react_component(component_class_name, props={}, html_options={})
推荐阅读
- javascript - 一旦所有字段都输入正确,如何使用 javascript 启用“创建帐户”按钮?
- python - 在 Sqlalchemy 中查询格式不正确以进行选择
- angular - 从外部 IP 连接到 Angular 和 springboot 应用程序
- javascript - 当我在 React 上滚动时如何移动按钮?
- java - Android:与相同模型的 Python 相比,TFLite 给出了错误的预测
- java - SpringBoot 白页
- winapi - 如何使用 win32 Visual C++ 检测 CD 是否在 CD ROM 托盘中
- python - 当随机库不起作用时会发生什么?
- javascript - 更改表单中按钮的类型后不会显示错误消息
- ruby - Ruby中具有多个返回值的函数的条件赋值?