feat: add custom hooks for typed useDispatch and useSelector

This commit is contained in:
siujamo
2026-05-07 10:46:06 +08:00
parent 1a16199f2f
commit af58edbafd
8 changed files with 52 additions and 8 deletions
+6
View File
@@ -0,0 +1,6 @@
import { useDispatch, useSelector } from "react-redux"
import type { AppDispatch, RootState } from "./index"
export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
export const useAppSelector = useSelector.withTypes<RootState>()
-3
View File
@@ -1,5 +1,4 @@
import { configureStore, combineReducers } from "@reduxjs/toolkit"
import { useDispatch, useSelector } from "react-redux"
import {
persistStore,
persistReducer,
@@ -46,5 +45,3 @@ export type RootState = ReturnType<typeof rootReducer>
export type AppDispatch = typeof store.dispatch
export type AppStore = typeof store
export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
export const useAppSelector = useSelector.withTypes<RootState>()