title: Pass PHP data to ReactJS
body: <p>I'm wondering what the best way to pass data that was fetched by PHP from a MySQL server to a React component is. Currently the only way I know is to simply echo the variable into the prop value, but I feel like there surely has to be a better way than this as it feels very hacky.</p>
  
  <p>I am new to React and have been looking for an API to use but haven't been able to find it (if it exists). I've also looked in the React documentation but it doesn't give any information either. </p>
  
  <p>Below is a very basic example of what I've been doing so far:</p>
  
  <pre><code>&lt;?php
  class User {
      //Name returned from mysql query.
      public $name = "Steve";
  }
  
  $user = new User;
  ?&gt;
  
  &lt;!DOCTYPE html&gt;
      &lt;body&gt;
          &lt;div id="greeting-div"&gt;&lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And my React component just looks like this: </p>
  
  <pre><code>  var Greeting = React.createClass({
      render: function() {
        return (
          &lt;p&gt;Hello, {this.props.name}&lt;/p&gt;
        )
      }
    });
  
    ReactDOM.render(
      &lt;Greeting name="&lt;?php echo json_encode($user-&gt;name); ?&gt;"/&gt;,
      document.getElementById('greeting-div')
    );
  </code></pre>
  
  <p>Is there a better way to do it or is this the right way?</p>