在React-On-Rails中使用react_component函数的渲染问题

时间:2018-12-27 14:31:51

标签: ruby-on-rails reactjs erb react-component react-on-rails

我正在尝试在React-on-Rails应用程序中显示React组件。但是,在我的def remove_duplicates(xs): """Removes duplicate elements from given list ”xs” """ result = [] for e in xs: if e not in xs: result.append(e) return result 文件中呈现组件时,我面临着一个奇怪的行为。

.html.erb文件中,我尝试了:

1)情况1:

.html.erb

在第一种情况下,react组件将不会显示,也不会引发任何错误。

2)情况2:

<div class="row search-container">
 <div>
  <%= react_component('MyComponent',
    props: {
      prop1: [],
      prop2: 'Hello world'
    },
    prerender: false) 
  %>
 </div>
</div>

行为与情况1相同。

3)情况3:

<div class="row search-container">
 <div></div> <!-- Div added here -->
 <div>
  <%= react_component('MyComponent',
    props: {
      prop1: [],
      prop2: 'Hello world'
    },
    prerender: false) 
  %>
 </div>
</div>

在第三种情况下,所有内容均正确显示。

我试图理解为什么添加一个字符串会使react组件呈现或不呈现。我可能在这里错过了一些东西,但是我无法解释这种行为。

请让我知道您是否遇到相同的问题,或者是否有任何线索可以帮助我了解我错过的事情。

0 个答案:

没有答案