matt-oakes / redux-devtools-expo-dev-plugin

The full Redux DevTools for Expo using a dev plugin
MIT License
51 stars 5 forks source link

Redux Toolkit #9

Closed LunatiqueCoder closed 3 months ago

LunatiqueCoder commented 4 months ago

Description:

Hello! Those suggestions made it possible for us to use this plugin with Redux Toolkit.

Should fix #4 and #8 Did not test with Redux Saga though

Changes:

Besides using the StoreEnhancer type exported by redux-toolkit instead of redux, the following setup made it possible for us with no errors, ts-ignore, or other hacks:

Using Redux Toolkit

Let's suppose your store looks something like this:

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

const defaultMiddlewareOptions = {
  serializableCheck: false,
  immutableCheck,
};

const middlewares = [apiSlice.middleware, resourcesApiSlice.middleware];

const store = configureStore({
  reducer: rootReducer,
  middleware: getDefaultMiddleware => getDefaultMiddleware(defaultMiddlewareOptions).concat(middlewares),
});

After adding the plugin it should look something like this:

import { StoreEnhancer, configureStore } from '@reduxjs/toolkit';
import devToolsEnhancer from 'redux-devtools-expo-dev-plugin';
import { applyMiddleware } from '@reduxjs/toolkit';

const defaultMiddlewareOptions = {
  serializableCheck: false,
  immutableCheck,
};

const middlewareEnhancer = applyMiddleware(
  apiSlice.middleware,
  resourcesApiSlice.middleware,
);

const store = configureStore({
  enhancers: getDefaultEnhancers =>
    getDefaultEnhancers().concat(middlewareEnhancer, devToolsEnhancer()),
  reducer: rootReducer,
  middleware: getDefaultMiddleware => getDefaultMiddleware(defaultMiddlewareOptions),
});
matt-oakes commented 3 months ago

Thank you for this. I have merged in just the changes to the README.

I can't merge in your changes from redux to @reduxjs/toolkit as this would break support for anyone using Redux without toolkit. I don't want using this dev tool to dictate how people have their Redux store setup, if possible. I'll look into alternatives to fix the type error that was mentioned.