react18 typeScript useSelector 提示state 类型未知

 

解决方案

store/index.tsx

import { configureStore } from '@reduxjs/toolkit';
import { useSelector, useDispatch } from 'react-redux'
import type { TypedUseSelectorHook } from 'react-redux'
import user from './modules/user';
import nav from './modules/nav';
const store = configureStore({
  reducer: {
    user,
    nav
  },
});
export type IRootState = ReturnType<typeof store.getState>
type AppDispatch = typeof store.dispatch
export const useAppSelector: TypedUseSelectorHook<IRootState> = useSelector
export const useAppDispatch: () => AppDispatch = useDispatch

export default store
 
页面使用

 

posted @ 2023-12-01 16:01  卢老师不想编程  阅读(188)  评论(1编辑  收藏  举报