I've recently set up the redux with my Next.js project, now i'm dealing with persisting redux data, so that on every page refresh, i can have the persist state. So i've added redux-persist for handling this scenario as it's the best solution with react-redux, but I don't know why it's not working here in next.js with next-redux-wrapper or withRedux library too. So kindly help me with this issue, is there anything like redux-persist existed ?(I don't want cookie's solution though), if yes, then kindly suggest me the references with examples, it will be really helpful. Thanks in advance...
I was actually trying to persist the redux state after every page refreshes, so i have used redux-persist with next-redux-wrapper too, but i'm getting errors
/store.js
import { createStore, applyMiddleware } from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension'
import thunkMiddleware from 'redux-thunk'
import { persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
const persistConfig = {
timeout: 0,
key: 'root',
storage,
};
const persistedReducer = persistReducer(persistConfig, reducer);
export default () => {
return createStore(persistedReducer,
composeWithDevTools(
applyMiddleware(
thunkMiddleware
)
));
};
/_app.js
import App, { Container } from 'next/app'
import React from 'react'
import { Provider } from 'react-redux'
import withRedux from 'next-redux-wrapper';
import { PersistGate } from 'redux-persist/integration/react';
import { persistStore } from 'redux-persist';
import store from '../store';
class MyApp extends App {
static async getInitialProps ({Component, ctx}) {
return {
pageProps: (Component.getInitialProps ? await Component.getInitialProps(ctx) : {})
};
}
render () {
const { Component, pageProps, reduxStore } = this.props;
const persistor = persistStore(store);
return (
<Container>
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<Component {...pageProps} />
</PersistGate>
</Provider>
</Container>
)
}
}
I expect it will persist the state, but I'm getting error like this : "redux-persist failed to create sync storage. falling back to memory storage.TypeError: baseReducer is not a function"