Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Better store enhancer APIs

Compare
Choose a tag to compare
@tptee tptee released this 28 Sep 04:01
· 241 commits to master since this release

We've overhauled the store enhancer API to require less fiddly and error-prone configuration!

On the browser:

// Install the router into the store for a browser-only environment
const clientOnlyStore = createStore(
  yourReducer,
  initialState,
  routerForBrowser({
    // The configured routes. Required.
    routes,
    // The basename for all routes. Optional.
    basename: '/example'
  })
);

For an Express route:

app.use('/*', (req, res) => {
  // Create the Redux store, passing in the
  // Express request to the store enhancer.
  // 
  // If you're using an Express sub-router,
  // routerForExpress will infer the basename
  // from req.baseUrl!
  const store = createStore(
    state => state,
    { what: 'ever' },
    routerForExpress({
      routes,
      request: req
    })
  );

  // ...then renderToString() your components as usual,
  // passing your new store to your <Provider> component.
  // 
  // Don't forget to attach your ESCAPED initialState to
  // a script tag in your template that attaches to
  // something like window.__INITIAL_STATE.
});

Major

New browser and Express store enhancer APIs with updated docs (#73)