Commit a9b4d62a authored by Rais Aryaguna's avatar Rais Aryaguna

feat: Add typed hooks for dispatch and selector in Redux store

parent 1748cbbe
......@@ -4,6 +4,8 @@
import { configureStore, combineReducers } from '@reduxjs/toolkit';
import { persistStore, persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';
import type { TypedUseSelectorHook } from 'react-redux';
import { useSelector, useDispatch } from 'react-redux';
import loginReducer from './auth/store/loginSlice';
import userReducer from './auth/store/userSlice';
......@@ -39,6 +41,12 @@ const persistedReducer = persistReducer(persistConfig, rootReducer);
export const store = configureStore({
reducer: persistedReducer,
devTools: true,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: {
ignoredActions: ['persist/PERSIST', 'persist/REHYDRATE'],
},
}),
});
// 5. Buat persistor
......@@ -47,3 +55,7 @@ export const persistor = persistStore(store);
// 6. TypeScript types
export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;
// 7. Typed hooks
export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment