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

Redux Toolkit #9

Closed
wants to merge 5 commits into from
Closed

Conversation

LunatiqueCoder
Copy link
Contributor

@LunatiqueCoder LunatiqueCoder commented Jun 17, 2024

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),
});

@LunatiqueCoder LunatiqueCoder changed the title Update README.md to use Redux Toolkit Redux Toolkit Jun 17, 2024
@matt-oakes
Copy link
Owner

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.

@matt-oakes matt-oakes closed this Jun 23, 2024
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

Successfully merging this pull request may close these issues.

Update README for RTK
2 participants