2023-05-09 14:56:26 +00:00
|
|
|
import { configureStore } from '@reduxjs/toolkit';
|
|
|
|
import { rootReducer } from '../reducers';
|
|
|
|
import { loadingBarMiddleware } from './middlewares/loading_bar';
|
|
|
|
import { errorsMiddleware } from './middlewares/errors';
|
|
|
|
import { soundsMiddleware } from './middlewares/sounds';
|
|
|
|
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux';
|
|
|
|
|
|
|
|
export const store = configureStore({
|
|
|
|
reducer: rootReducer,
|
2023-05-09 21:41:18 +00:00
|
|
|
middleware: (getDefaultMiddleware) =>
|
|
|
|
getDefaultMiddleware()
|
|
|
|
.concat(
|
|
|
|
loadingBarMiddleware({
|
|
|
|
promiseTypeSuffixes: ['REQUEST', 'SUCCESS', 'FAIL'],
|
|
|
|
})
|
|
|
|
)
|
2023-05-09 14:56:26 +00:00
|
|
|
.concat(errorsMiddleware)
|
|
|
|
.concat(soundsMiddleware()),
|
|
|
|
});
|
|
|
|
|
|
|
|
// Infer the `RootState` and `AppDispatch` types from the store itself
|
2023-05-09 21:41:18 +00:00
|
|
|
export type RootState = ReturnType<typeof rootReducer>;
|
2023-05-09 14:56:26 +00:00
|
|
|
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
|
2023-05-09 21:41:18 +00:00
|
|
|
export type AppDispatch = typeof store.dispatch;
|
2023-05-09 14:56:26 +00:00
|
|
|
|
|
|
|
export const useAppDispatch: () => AppDispatch = useDispatch;
|
|
|
|
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
|