store.dispatch is not a function - react native redux-persist with redux-thunk middlware

Akram

I am new to redux-persist and i am trying persist my states to local storage. Getting the above error.

I looked up in Stack Overflow for a solution but couldn't find a similar issue with a solution here. any help would be highly appreciated.

here is my store code:

import { createStore, applyMiddleware, compose } from "redux";
import thunk from "redux-thunk";
import { createLogger } from "redux-logger";
import { createReactNavigationReduxMiddleware } from "react-navigation-redux-helpers";
import appReducer from "../reducers";


const persistConfig = {
  key: 'tcroot',
  storage: LocalStorage,
}

const persistedReducer = persistReducer(persistConfig, appReducer)

// instantiate logger middleware
const logger = createLogger();
const middleware = createReactNavigationReduxMiddleware(state => state.nav);

const composeEnhancers =
  (typeof window !== "undefined" &&
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
  compose;

const configureStore = () =>
  createStore(
    persistedReducer,
    composeEnhancers(applyMiddleware(thunk, logger, middleware))
  );


export default configureStore;

and my app.js code :

import React, { Component } from "react";
import { Provider } from "react-redux";
import { PersistGate } from 'redux-persist/integration/react'
import configureStore from "./redux/store";
// import store from "./redux/store/dev";
import persistor from './redux/store/persistedStore';

import AppContainer from "./screens/AppContainer";

// const { store, persistor } = configureStore();
const store = configureStore();

export default class App extends Component {
  render() {
    return (
      <Provider store={store}>
        <PersistGate loading={null} persistor={persistor}>
          <AppContainer />
        </PersistGate>
      </Provider>
    );
  }
}

enter image description here

Tung Duong

The issue is your configureStore doesn't return persistor

Need like this

import { persistStore, persistReducer } from 'redux-persist'
//....

const configureStore = () => {
  let store = createStore(
    persistedReducer,
    composeEnhancers(applyMiddleware(thunk, logger, middleware))
  );
  let persistor = persistStore(store)
  return { store, persistor }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Redux Persist TypeError: store.dispatch is not a function

Redux-thunk "dispatch is not a function"

Redux-thunk: `dispatch is not a function`

Redux-Persist - how to conditionally persist the store in react native

Redux thunk: wait for async function to dispatch

How dispatch function with Redux-thunk

Dispatch is not a function react redux

Why is the thunk function in React Native Redux not working, but the action function does?

React native Redux dispatch is not a function, dispatch is an instance of Object

Dispatch in Redux-Thunk

React-Native Redux-Toolkit Redux-Persist: Cannot read property 'dispatch' of undefined

React Native Navigation and Redux Persist

middlware is not a function in react native

return promise from store after redux thunk dispatch

React Native + Redux - onPress dispatch an action and another function

Dispatch function in React-Redux

React, Redux and Recompose: "dispatch is not a function"

Function after dispatch React Redux

React Redux, dispatch dynamic function

Async call with react native and redux , thunk

Weird behavior of Redux thunk in a React Native app

redux-thunk dispatch events

Redux-thunk dispatch not working

store.getState is not a function Redux-persist

Use Custom Async middleware to dispatch - Redux Thunk - react Router

Redux-thunk dispatch function doesn't work on Laravel

Redux-Thunk Chaining Actions, getting a "dispatch(...) then is not a function error

Redux thunk not resolving before next action + then is not a function or dispatch undefined

redux persist data not shown react native