Change AsyncStorage with MMKV in redux persist

104 views Asked by At

I'm trying to migrate my app from AsyncStorage to MMKV. I'm using redux toolkit and redux toolkit. I've found some resources that are using that but I'm not able to understand why they are doing it. They are creating functions set and get with key and value and they're creating a middleware and adding it to redux store. Please can someone explain to me what should I do to accomplish this thing. This my store code.

Th app is not yet published, so I don't care about user data. I want to change AsyncStorage with MMKV in my app.

import { configureStore } from '@reduxjs/toolkit';

import { combineReducers } from 'redux';

import { persistReducer } from 'redux-persist';

import { profileSlice } from 'features/user/store/profile-slice';

import thunk from 'redux-thunk';

import AsyncStorage from '@react-native-async-storage/async-storage';

import { garageSlice } from 'features/garage/store/garage-slice';



const reducers = combineReducers({

  profile: profileSlice.reducer,

  garage: garageSlice.reducer,

});



const persistConfig = {

  key: 'root',

  storage: AsyncStorage,

};



let middlewares = [thunk];

if (__DEV__) {

  const createDebugger = require('redux-flipper').default;

  middlewares = [...middlewares, createDebugger()];

}



const persistedReducer = persistReducer(persistConfig, reducers);



export const store = configureStore({

  reducer: persistedReducer,

  devTools: process.env.NODE_ENV !== 'production',

  middleware: middlewares,

});

export type AppDispatch = typeof store.dispatch;

export type RootState = ReturnType<typeof store.getState>;

What are the modifications that I should do to migrate from AsyncStorage to MMKV ?

0

There are 0 answers