I'm just learning React, and while I understand many of the basics there is one concept I haven't seen anyone cover: how do I take information loaded via the server-side language (e.g. PHP) and use it when loading up the React view?
I would have expected that I'd just have the RenderDom
call in my php view, such as:
// In the pre-compiled JSX file
var Greeting = React.createClass({
render: function() {
<div>
<h1>Hello, { this.props.username }</h1>
</div>
}
});
// In my PHP view
<script type="text/jsx">
ReactDOM.render( <Greeting username="<?php echo $username; ?>"/>, document.body );
</script>
But that doesn't work; nothing is displayed. I'm thinking that's because the text/jsx
script area doesn't get executed...but of course if I remove that there's a syntax error.
Soo...I'm just wondering, what's the typical method for taking data loaded up from the DB and passing it into a React component?