Skip to content

Commit

Permalink
fix(using-redux): create a fresh store for each SSR page (#11134)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpboyd authored and pieh committed Feb 5, 2019
1 parent aa2223e commit ec8deb2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions examples/using-redux/wrap-with-provider.js
Expand Up @@ -3,7 +3,11 @@ import { Provider } from "react-redux"

import createStore from "./src/state/createStore"

const store = createStore()

// eslint-disable-next-line react/display-name,react/prop-types
export default ({ element }) => <Provider store={store}>{element}</Provider>
export default ({ element }) => {
// Instantiating store in `wrapRootElement` handler ensures:
// - there is fresh store for each SSR page
// - it will be called only once in browser, when React mounts
const store = createStore()
return <Provider store={store}>{element}</Provider>
}

0 comments on commit ec8deb2

Please sign in to comment.