title: Is window.__INITIAL_STATE__ still the preferred way to pass initial state to the client in React Universal apps?
body: <p>I'm currently reading <a href="http://amzn.to/2p4bfsE" rel="noreferrer">a book</a> about React and Universal apps in which the author claims that the following is best practice to pass initial state from server to client:</p>
  
  <p><strong>server.js</strong></p>
  
  <pre><code>import React from 'react';
  import {renderToStaticMarkup} from 'react-dom/server';
  import Myapp from '../MyApp';
  import api from '../services';
  
  function renderPage(html, initialData) {
      return `
          &lt;html&gt;
              &lt;body&gt;
                  ${html}
              &lt;/body&gt;
              &lt;script&gt;
                  window.__INITIAL_STATE__ = ${JSON.stringify(initialData)};
              &lt;/script&gt;
              &lt;script src="bundle.js"&gt;&lt;/script&gt;
          &lt;/html&gt;
      `;
  }
  
  export default function(request, reply) {
      const initialData = api.getData();
      const html = renderToStaticMarkup(&lt;MyApp /&gt;);
      reply(renderPage(html, initialData);
  }
  </code></pre>
  
  <p>And then, in the client you would read out the data like this:</p>
  
  <p><strong>bundle.js</strong></p>
  
  <pre><code>const initialData = window.__INITIAL_STATE__ || {};
  const mountNode = document.getElementById('root');
  ReactDOM.render(&lt;MyApp /&gt;, mountNode);
  </code></pre>
  
  <p>From what I understand is that the initial state first gets converted to a string and then attached as a global object literal to the window object.</p>
  
  <p>This solution looks very rough to me. The book was released in mid 2016. Is usage of <code>window.__INITIAL_STATE__</code> still the way how to do this or are there better solutions?</p>
  
  <p>For example, I could imagine that it would be possible to offer the initial state in a separate micro service call which then could also be cached better than if the data is embedded directly into the document because then the initial state data has to be transferred every time the page refreshes, even if the data hasn't changed.</p>