diff --git a/src/app/listenerMiddleware.ts b/src/app/listenerMiddleware.ts new file mode 100644 index 0000000..cc6889d --- /dev/null +++ b/src/app/listenerMiddleware.ts @@ -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; + +export const startAppListening = + listenerMiddleware.startListening as AppStartListening; +export const addAppListener = addListener as TypedAddListener< + RootState, + AppDispatch +>; diff --git a/src/app/store.ts b/src/app/store.ts index d197f64..bf908e1 100644 --- a/src/app/store.ts +++ b/src/app/store.ts @@ -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, });