Ruby on rails 如何在rails中使用npm中的react组件
我是react的新手,我关注这篇文章 在rails应用程序中使用react,一切正常。但后来我想在Ruby on rails 如何在rails中使用npm中的react组件,ruby-on-rails,reactjs,npm,summernote,Ruby On Rails,Reactjs,Npm,Summernote,我是react的新手,我关注这篇文章 在rails应用程序中使用react,一切正常。但后来我想在records.htmlpage(WYSIWYG html编辑器)中包含。我发现这个npm模块,无法使编辑器工作 这是我的代码(请尝试1): application.js index.html.erb index.html.erb 我犯了这个错误 react.self-e3251ec…js?body=1:1285警告:react.createElement:类型不应为null、未定义
records.html
page(WYSIWYG html编辑器)中包含。我发现这个npm模块,无法使编辑器工作
这是我的代码(请尝试1):
- application.js
- index.html.erb
- index.html.erb
我犯了这个错误
react.self-e3251ec…js?body=1:1285警告:react.createElement:类型不应为null、未定义、布尔或数字。它应该是字符串(对于DOM元素)或ReactClass(对于复合组件)。检查构造函数的呈现方法
有些东西值得检查
我假设您的节点包正在安装到/node\u modules/*
。确保这些包已添加到您的资产管道中。我过去常常做到这一点
在浏览器控制台中检查是否设置了变量(只需键入ReactSummernote
。如果正确导入,则结果应为函数;如果出现问题,则结果应为未定义)
如果您已经走到了这一步,但仍然卡住了,我建议您在不使用react rails的情况下触发渲染。通过普通javascript在页面上呈现组件是很容易的,如果是react rails gem导致了问题,那么可以使用类似的方法轻松地在页面上导航
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('example')
);
ReactDOM.render(
你好,世界!,
document.getElementById('示例')
);
非常感谢您这样做:“检查您的浏览器控制台,看看是否设置了变量(只需键入ReactSummernote。如果正确导入,结果应该是函数,如果出现问题,则结果应该是未定义的)。”
<%= react_component 'ReactSummernote'%>
@RichTextEditor = React.createClass
render: ->
React.createElement ReactSummernote
<%= react_component 'RichTextEditor'%>
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('example')
);