Skip to content

Instantly share code, notes, and snippets.

@bingex
Last active October 10, 2021 18:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bingex/7778cce3f4e183c923d5d0d3aaf23eaf to your computer and use it in GitHub Desktop.
Save bingex/7778cce3f4e183c923d5d0d3aaf23eaf to your computer and use it in GitHub Desktop.
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);
@stever
Copy link

stever commented Oct 10, 2021

Thank-you for the example code. This helped me get my Redux-Sagas code working with Next.js :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment