I have a React app like this.
var X = React.createClass({
componentDidMount: function() {
fetch(this.props.feed).then(...);
}
render: function() {
return <div>{this.props.feed}</div>
}
});
The feed prop is used to get a JSON feed in componentDidMount that's unique for a particular customer.
It would be convenient to pass data into my React app from the HTML to parameterise it:
<html>
<body>
<div id="app" feed='custom_feed.json'></div>
</body>
</html
My current solution looks like this:
var root = document.getElementById('app');
var feed = root.getAttribute('feed')
ReactDOM.render(<X feed={feed}/>, root);
This obviously works, but it feels like there ought to be a more idiomatic solution. Is there a more React way to do this?
<x z='z'></x>
onto the page. I'm obviously being wrongheaded about this.