Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
81802d2e
Commit
81802d2e
authored
Jun 13, 2018
by
Lon Ilesanmi
Committed by
Tim Neutkens
Jun 13, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up Redux example (#4594)
- Remove unused imports - Edit some comments - Rename Wrapper App Class
parent
4f4b7a1b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
6 deletions
+7
-6
with-redux-store.js
examples/with-redux/lib/with-redux-store.js
+7
-6
No files found.
examples/with-redux/lib/with-redux-store.js
View file @
81802d2e
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 clien
t
//
Create store if unavailable on the client and set it on the window objec
t
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
AppWith
Redux
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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment