[英]What is the correct way of initializing react component with data?
I'm learning react.js with rails using react-rails
. 我正在使用
react-rails
使用rails学习react.js。 App is basically list of sport events. 应用程式基本上是体育赛事清单。
What is better way of initializing my main component with data? 用数据初始化我的主要组件的更好方法是什么?
<%= react_component('EventsBox', {url: events_path(format: 'json')}, {prerender: true)} %>
And then make an ajax request to upload data from this url in componentDidMount
. 然后发出ajax请求以从
componentDidMount
该URL上传数据。
or 要么
<%= react_component('EventsBox',{data: Event.all.as_json},{prerender: true)} %>
如果要使用数据进行预渲染,则选项2是您想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.