How To Pass Props From Template To React Root Node?
Solution 1:
It is possible to pass props to the root element through data attributes and pass them to root element in index.js
<div
id="root"
data-custom-props='{aKey: "a value"}'
></div>
index.js file:
ReactDOM.render(<App {...(root.dataset)}/>, root);
Solution 2:
A common pattern is to output a json string into a script tag, which you can then refer to in your init function.
For example:
// Above where you include your main bundle
<script>window.__INITIAL_STATE.__ = { your: 'DATA', encodedIn: 'json', here: true }
</script>
You can then reference window.__INITIAL_STATE__
in your index.js and pass data as props into your root component.
Solution 3:
What data do you want to pass to react? Props is the concept that allow user to pass data from one component to another within react. It is not made to pass data from outside world to react app.
I believe this answer can guide you in right direction. How to get Django and ReactJS to work together?
also read following to get some idea of back-end and front-end working together. http://geezhawk.github.io/using-react-with-django-rest-frameworkhttp://www.openmindedinnovations.com/blogs/3-ways-to-integrate-ruby-on-rails-react-flux
Post a Comment for "How To Pass Props From Template To React Root Node?"