yarn react-redux 9.1.0
v9.1.0

latest releases: 9.1.2, 9.1.1
3 months ago

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:

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:

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: v9.0.4...v9.1.0

Don't miss a new react-redux release

NewReleases is sending notifications on new releases.