Setup typescripted listenerMiddleware

develop
Jason Zhu 2023-04-04 23:12:22 +10:00
parent f30edc9700
commit 19c189c37d
2 changed files with 18 additions and 1 deletions

View File

@ -0,0 +1,13 @@
import { createListenerMiddleware, addListener } from '@reduxjs/toolkit';
import type { TypedStartListening, TypedAddListener } from '@reduxjs/toolkit';
import { AppDispatch, RootState } from 'app/store';
export const listenerMiddleware = createListenerMiddleware();
export type AppStartListening = TypedStartListening<RootState, AppDispatch>;
export const startAppListening =
listenerMiddleware.startListening as AppStartListening;
export const addAppListener = addListener as TypedAddListener<
RootState,
AppDispatch
>;

View File

@ -1,4 +1,5 @@
import { configureStore } from '@reduxjs/toolkit';
import { listenerMiddleware } from './listenerMiddleware';
import { pokedexApi } from 'features/Pokedex/pokedexApi';
import { pokedexSlice } from 'features/Pokedex/pokedexSlice';
@ -11,7 +12,10 @@ export const store = configureStore({
[pokedexApi.reducerPath]: pokedexApi.reducer,
},
middleware: getDefaultMiddleware =>
getDefaultMiddleware().concat(pokedexApi.middleware),
getDefaultMiddleware().concat(
pokedexApi.middleware,
listenerMiddleware.middleware,
),
devTools: true,
});