提交 81802d2e 编写于 作者: L Lon Ilesanmi 提交者: Tim Neutkens

Clean up Redux example (#4594)

- Remove unused imports

- Edit some comments

- Rename Wrapper App Class
上级 4f4b7a1b
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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册