functiongetOrCreateStore(initialState) { // Always make a new store if server, otherwise state is shared between requests if (isServer) { return initializeStore(initialState); }
// Create store if unavailable on the client and set it on the window object if (!window[__NEXT_REDUX_STORE__]) { window[__NEXT_REDUX_STORE__] = initializeStore(initialState); } returnwindow[__NEXT_REDUX_STORE__]; }
// Get or Create the store with `undefined` as initialState // This allows you to set a custom default initialState //const reduxStore = getOrCreateStore()
// Provide the store to getInitialProps of pages appContext.ctx.reduxStore = reduxStore;
let appProps = {}; if (typeof App.getInitialProps === "function") { appProps = await App.getInitialProps(appContext); }