JSON object vs window variable for passing server-side rendered initial state using reactjs
In an isomorphic application with Reactjs, you need to pass the identical initial state that was rendered on the server down to the client (which will then 'rehydrate' the app with event bindings and such). I've seen two approaches to passing this initial state down-- Setting a global variable to the window: <script> window.initialState = {{JSON.stringify(initialState)}} ; </script> Or passing it as a JSON object: <script id="initial-state" type="application/json"> {{JSON.stringify(initialState)}}</script> Both are easily retrievable from anywhere in the application. Are there any advantages