Skip to content

Commit ee717af

Browse files
stephenmathiesonrauchg
authored andcommitted
examples/with-redux: remove global store (vercel#908)
This patch removes the global `store` on the client. IMO this example should avoid polluting the global namespace with simple scoping tricks can solve the problem equally as well.
1 parent db50fc7 commit ee717af

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

examples/with-redux/store.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ export const startClock = () => dispatch => {
1212
return setInterval(() => dispatch({ type: 'TICK', light: true, ts: Date.now() }), 800)
1313
}
1414

15+
let store = null
16+
1517
export const initStore = (reducer, initialState, isServer) => {
1618
if (isServer && typeof window === 'undefined') {
1719
return createStore(reducer, initialState, applyMiddleware(thunkMiddleware))
1820
} else {
19-
if (!window.store) {
20-
window.store = createStore(reducer, initialState, applyMiddleware(thunkMiddleware))
21+
if (!store) {
22+
store = createStore(reducer, initialState, applyMiddleware(thunkMiddleware))
2123
}
22-
return window.store
24+
return store
2325
}
2426
}

0 commit comments

Comments
 (0)