使用react_component()在haml文件中添加React组件 [英] Using react_component() to add react components in haml files
问题描述
While working with the react-rails
library, we can use the react_component() function in an .erb
file to add a react component.
我们如何在 .haml
文件中使用相同的功能?还是我们有另一种在haml文件中添加react组件的方法?
How can we use the same function in a .haml
file? Or do we have another way of adding a react component in a haml file?
推荐答案
如果在RoR项目中设置了webpacker,则只需使用 react-rails 中的
react_component
函数即可.code>,我们将红宝石代码添加到haml文件中.
If webpacker is setup in your RoR project, then you can simply use the react_component
function from react-rails
in the same way we would add ruby code to the haml file.
例如:
%li
= react_component("ReactComponent")
这应该可以正常工作.默认情况下,Webpacker会尝试在 app/javascript/components
中找到React组件.
This should work correctly. Webpacker will try to locate the React component in app/javascript/components
by default.
这篇关于使用react_component()在haml文件中添加React组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!