We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
中文官网链接 其中useAppDispatch 这个 hook 如果这样使用会报错,应该这样使用export const useAppDispatch = () => useDispatch<AppDispatch>()
export const useAppDispatch = () => useDispatch<AppDispatch>()
// app/store.ts import { configureStore } from '@reduxjs/toolkit' // ... const store = configureStore({ reducer: { posts: postsReducer, comments: commentsReducer, users: usersReducer } }) // 从 store 本身推断出 `RootState` 和 `AppDispatch` 类型 export type RootState = ReturnType<typeof store.getState> // 推断出类型: {posts: PostsState, comments: CommentsState, users: UsersState} export type AppDispatch = typeof store.dispatch
// app/hooks.ts import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux' import type { RootState, AppDispatch } from './store' // 在整个应用程序中使用,而不是简单的 `useDispatch` 和 `useSelector` export const useAppDispatch: () => AppDispatch = useDispatch export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
The text was updated successfully, but these errors were encountered:
No branches or pull requests
中文官网链接
其中useAppDispatch 这个 hook 如果这样使用会报错,应该这样使用
export const useAppDispatch = () => useDispatch<AppDispatch>()
The text was updated successfully, but these errors were encountered: