【问题标题】:How can I pass children to a component in a slim template using react_rails如何使用 react_rails 将子项传递给苗条模板中的组件
【发布时间】:2020-06-15 16:11:24
【问题描述】:

我正在使用react_rails 在 Ruby on Rails 应用程序中的超薄模板内渲染反应组件。有没有办法将子组件传递给 React 组件,在该组件中,子组件以苗条的形式呈现在服务器端?

这是我最想要的:

<MyComponent>
  <p>my custom content</p>
</MyComponent>

内容来自模板本身,如下所示:

= react_component 'MyComponent' do 
  p my custom content

这可能吗?如果是这样,将孩子传递给 react_component 的最佳方法是什么?

【问题讨论】:

    标签: ruby-on-rails reactjs slim-lang react-rails


    【解决方案1】:

    在页面加载时,react_ujs 驱动程序将扫描页面并使用 data-react-class 和 data-react-props 装载组件。

    视图助手的签名是: react_component(component_class_name, props={}, html_options={})

    【讨论】:

      猜你喜欢
      • 2023-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-09
      • 2019-12-17
      • 1970-01-01
      • 1970-01-01
      • 2020-12-02
      相关资源
      最近更新 更多