Name | Modified | Size | Downloads / Week |
---|---|---|---|
Parent folder | |||
README.md | 2024-01-05 | 3.6 kB | |
v5.1.0 source code.tar.gz | 2024-01-05 | 1.6 MB | |
v5.1.0 source code.zip | 2024-01-05 | 1.7 MB | |
Totals: 3 Items | 3.3 MB | 0 |
This minor release:
- Adds a new createSelector.withTypes<RootState>()
and createStructuredSelector.withTypes<RootState>()
API
- Deprecates the TypedStructuredSelectorCreator
type introduced in 5.0
- Aims to reduce false positives in identityFunctionCheck
by only running if the output selector is passed one argument
- Fixes a bug with weakMapMemoize
's resultEqualityCheck
when used with a primitive result.
withTypes
Most commonly, selectors will accept the root state of a Redux store as their first argument. withTypes
allows you to specify what that first argument will be ahead of creating the selector, meaning it doesn't have to be specified.
:::ts
// previously
export const selectPostById = createSelector(
[
(state: RootState) => state.posts.entities,
(state: RootState, id: number) => id,
],
(entities, id) => entities[id],
);
// now
export const createAppSelector = createSelector.withTypes<RootState>();
export const selectPostById = createAppSelector(
[(state) => state.posts.entities, (state, id: number) => id],
(entities, id) => entities[id],
);
Known limitations
Due to a Typescript issue, inference of the output selector's parameters only works with withTypes
when using an array of input selectors.
If using the variadic version, you can either wrap your input selectors in an array instance (as above), or annotate the parameters manually.
:::ts
export const createAppSelector = createSelector.withTypes<RootState>();
export const selectPostById = createAppSelector(
(state) => state.posts.entities,
(state, id: number) => id,
// parameters cannot be inferred, so need annotating
(entities: Record<number, Post>, id: number) => entities[id],
);
What's Changed
- Reduce
identityFunctionCheck
false positives by @Methuselah96 in https://github.com/reduxjs/reselect/pull/660 - Fix cut content inside TOC of docs by @aryaemami59 in https://github.com/reduxjs/reselect/pull/664
- Remove redundant Svg requires from components in docs by @aryaemami59 in https://github.com/reduxjs/reselect/pull/665
- Fix
_lastResult.deref
is not a function (it is undefined) in React Native and Expo applications by @aryaemami59 in https://github.com/reduxjs/reselect/pull/671 - Update getting-started.mdx by @cchaonie in https://github.com/reduxjs/reselect/pull/672
- Update createSelectorCreator.mdx with correct defaults by @lukeapage in https://github.com/reduxjs/reselect/pull/674
- Introduce pre-typed
createSelector
viacreateSelector.withTypes<RootState>()
method by @aryaemami59 in https://github.com/reduxjs/reselect/pull/673 - Bump RTK and React-Redux to latest versions by @aryaemami59 in https://github.com/reduxjs/reselect/pull/676
- add publish job by @EskiMojo14 in https://github.com/reduxjs/reselect/pull/677
- Wrap up implementation of
TypedStructuredSelectorCreator
by @aryaemami59 in https://github.com/reduxjs/reselect/pull/667 - Introduce pre-typed
createStructuredSelector
viacreateStructuredSelector.ts.withTypes<RootState>()
method by @aryaemami59 in https://github.com/reduxjs/reselect/pull/678 - Bump
vitest
to v1 by @aryaemami59 in https://github.com/reduxjs/reselect/pull/668
New Contributors
- @Methuselah96 made their first contribution in https://github.com/reduxjs/reselect/pull/660
- @cchaonie made their first contribution in https://github.com/reduxjs/reselect/pull/672
Full Changelog: https://github.com/reduxjs/reselect/compare/v5.0.1...v5.1.0