reduxjs / redux

A JS library for predictable global state management
https://redux.js.org
MIT License
60.54k stars 15.28k forks source link

Missing AppStore from file #4703

Closed MarcHbb closed 3 weeks ago

MarcHbb commented 3 weeks ago

What docs page needs to be fixed?

What is the problem?

When explaining how to type hooks, you import a type that doesn't exist :

import { useDispatch, useSelector, useStore } from 'react-redux'
import type { AppDispatch, AppStore, RootState } from './store'.   <===== AppStore doesn't exist in ./store

// Use throughout your app instead of plain `useDispatch` and `useSelector`
export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
export const useAppSelector = useSelector.withTypes<RootState>()
export const useAppStore = useStore.withTypes<AppStore>()

This is the store file as you wrote it at the beginning of the section :

import { configureStore } from '@reduxjs/toolkit'
// ...

export const store = configureStore({
  reducer: {
    posts: postsReducer,
    comments: commentsReducer,
    users: usersReducer
  }
})

// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType<typeof store.getState>
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
export type AppDispatch = typeof store.dispatch

There's no mention of AppStore in this file, thus you import it in the hook file

What should be changed to fix the problem?

EskiMojo14 commented 3 weeks ago

raised #4704 to fix, thanks!