import { TypedUseSelectorHook , useDispatch , useSelector } from 'react-redux' ; import { configureStore } from '@reduxjs/toolkit' ; import { counterSlice } from './services/counter/slice' ; import { createActionListenerMiddleware , ActionListenerMiddlewareAPI , ActionListenerMiddleware , } from '@rtk-incubator/action-listener-middleware' ; import { themeSlice } from './services/theme/slice' ; import { setupCounterListeners } from './services/counter/listeners' ; import { setupThemeListeners } from './services/theme/listeners' ; const actionListenerMiddleware = createActionListenerMiddleware ( { onError : ( ) => console . error , } ) ; const store = configureStore ( { reducer : { [ counterSlice . name ] : counterSlice . reducer , [ themeSlice . name ] : themeSlice . reducer , } , middleware : ( gDM ) => gDM ( ) . prepend ( actionListenerMiddleware ) , } ) ; export { store } ; export type RootState = ReturnType < typeof store . getState > ; export type AppDispatch = typeof store . dispatch ; export type AppListenerApi = ActionListenerMiddlewareAPI < RootState , AppDispatch > ; export type AppActionListenerMiddleware = ActionListenerMiddleware < RootState , AppDispatch > ; export const appActionListener = actionListenerMiddleware as AppActionListenerMiddleware ; export const useAppDispatch = ( ) => useDispatch < AppDispatch > ( ) ; export const useAppSelector = useSelector ; setupCounterListeners ( appActionListener ) ; setupThemeListeners ( appActionListener ) ;