source code: src/server/index.js
- Fetch the initial state from backend API, here is src/common/api/counter.js
- Create
redux store
with that initial state - Use
renderToString()
fromreact-dom/server
to render component (wrapped inside redux store/Provider) into string - create stringified html, inside that:
- put stringified react component from step 3 inisde DOM.
- serialize the state of store and set as a global varaible
window.__PRELOADED_STATE__
- put client side js bundle (assests) into
script
so that can load in client side.
- retur the html to client
source code: src/client/index.js
- get the html
- At this point: html is contentful with initial state with also pure static information.
- SEO friendly achieved.
- download js bundle
- hydrate the app with
window.__PRELOADED_STATE__
- At this point: the page is interactable
source code: ./node_modules/razzle/scripts/build.js
Create and start the example:
npx create-razzle-app --example with-redux with-redux
cd with-redux
yarn start
Almost 100% of the code is taken from the official Redux universal example.