1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Clean up Redux example (#4594)

- Remove unused imports

- Edit some comments

- Rename Wrapper App Class
This commit is contained in:
Lon Ilesanmi 2018-06-13 13:40:59 +01:00 committed by Tim Neutkens
parent 4f4b7a1bce
commit 81802d2e60

View file

@ -1,5 +1,4 @@
import App, {Container} from 'next/app'
import {Provider} from 'react-redux'
import React from 'react'
import {initializeStore} from '../store'
const isServer = typeof window === 'undefined'
@ -11,7 +10,7 @@ function getOrCreateStore(initialState) {
return initializeStore(initialState)
}
// Store in global variable if client
// 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)
}
@ -19,16 +18,18 @@ function getOrCreateStore(initialState) {
}
export default (App) => {
return class Redux extends React.Component {
return class AppWithRedux extends React.Component {
static async getInitialProps (appContext) {
// 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 (App.getInitialProps) {
appProps = await App.getInitialProps(appContext)
if (typeof App.getInitialProps === 'function') {
appProps = await App.getInitialProps.call(App, appContext)
}
return {