Download Latest Version v9.2.0 source code.zip (1.7 MB)
Email in envelope

Get an email when there's a new version of React Redux

Home / v9.1.0
Name Modified Size InfoDownloads / Week
Parent folder
README.md 2024-01-12 1.9 kB
v9.1.0 source code.tar.gz 2024-01-12 1.6 MB
v9.1.0 source code.zip 2024-01-12 1.7 MB
Totals: 3 Items   3.2 MB 0

This minor release adds a new syntax for pre-typing hooks.

.withTypes

Previously, the approach for "pre-typing" hooks with your app settings was a little varied. The result would look something like the below:

:::ts
import type { TypedUseSelectorHook } from "react-redux"
import { useDispatch, useSelector, useStore } from "react-redux"
import type { AppDispatch, AppStore, RootState } from "./store"

export const useAppDispatch: () => AppDispatch = useDispatch
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector
export const useAppStore = useStore as () => AppStore

React Redux v9.1.0 adds a new .withTypes method to each of these hooks, analogous to the .withTypes method found on Redux Toolkit's createAsyncThunk.

The setup now becomes:

:::ts
import { useDispatch, useSelector, useStore } from "react-redux"
import type { AppDispatch, AppStore, RootState } from "./store"

export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
export const useAppSelector = useSelector.withTypes<RootState>()
export const useAppStore = useStore.withTypes<AppStore>()

What's Changed

New Contributors

Full Changelog: https://github.com/reduxjs/react-redux/compare/v9.0.4...v9.1.0

Source: README.md, updated 2024-01-12