Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: next is not a function #80

Open
JimLynchCodes opened this issue Oct 27, 2017 · 1 comment
Open

TypeError: next is not a function #80

JimLynchCodes opened this issue Oct 27, 2017 · 1 comment

Comments

@JimLynchCodes
Copy link

Hi, I'm trying to add persistState , but it's giving me this error:

TypeError: next is not a function
(anonymous function)
C:/Git-Projects/reacttr/node_modules/redux-localstorage/lib/persistState.js:70
  67 |   console.warn('Failed to retrieve initialize state from localStorage:', e);
  68 | }
  69 | 
> 70 | var store = next(reducer, finalInitialState, enhancer);
  71 | var slicerFn = slicer(paths);
  72 | 
  73 | store.subscribe(function () {
View compiled

Here's my store.js file:

import {applyMiddleware, createStore} from 'redux';
import {composeWithDevTools} from 'redux-devtools-extension';
import ReduxLogger from 'redux-logger';
import thunk from 'redux-thunk';
import promise from 'redux-promise-middleware';
import reducer from '../reducers';
import persistState from 'redux-localstorage';

const middleware = applyMiddleware(persistState(), promise(), thunk, ReduxLogger);

const initialState = {
};

function getHeaderTooltip(headerName) {
  return "sum(" + headerName.toString() + ")";
}

export default createStore(reducer, initialState, composeWithDevTools(middleware));
@marcelorl
Copy link

I've figure out how to use it. This error happens, when we try to add redux-localstorage to applyMiddleware function, like this:

const middlewares = applyMiddleware(
  thunkMiddleware,
  persistState(['cart'])
);

createStore accepts as a second parameter middlewares or an enhancer.

Then, your code would be something like this:

import { combineReducers, createStore, applyMiddleware, compose } from 'redux';

const reducers = combineReducers({
  cart: cartReducer
});

const middlewares = applyMiddleware(
  thunkMiddleware
);

const configureStore =
  createStore(
    reducers,
    compose(
      middlewares,
      persistState(['cart'])
    )
  );

Pretty simple. I hope I still may help someone.

This issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants