Last active
October 10, 2021 18:08
-
-
Save bingex/7778cce3f4e183c923d5d0d3aaf23eaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore, applyMiddleware } from 'redux'; | |
import createSagaMiddleware from 'redux-saga'; | |
import { createWrapper } from 'next-redux-wrapper'; | |
import rootReducer from './rootReducer'; | |
import rootSaga from './rootSaga'; | |
export const makeStore = () => { | |
// 1: Create the middleware | |
const sagaMiddleware = createSagaMiddleware(); | |
// 2: Add an extra parameter for applying middleware | |
const store = createStore(rootReducer, applyMiddleware(sagaMiddleware)); | |
// 3: Run your sagas on server | |
store.sagaTask = sagaMiddleware.run(rootSaga); | |
// 4: now return the store | |
return store; | |
}; | |
export const wrapper = createWrapper(makeStore); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank-you for the example code. This helped me get my Redux-Sagas code working with Next.js :)