Questions tagged [reselect]

Reselect is a selector library for Redux.

Reselect is a selector library which uses memoization. It was originally written to compute derived data from -like applications state, but it's not strictly coupled to any specific architecture/library.

Reselect keeps a copy of the last inputs/outputs of the last call, and recomputes the result ONLY IF one of the inputs changes. If the the same inputs are provided twice in a row, Reselect return the cached saved output.

Reselect's memoization and caching are fully customizable.


Resources

387 questions
60
votes
7 answers

Use reselect selector with parameters

How do I pass additional parameters to combined selectors? I am trying to • Get data • Filter data • Add custom value to my data set / group data by myValue export const allData = state => state.dataTable export const filterText = state =>…
Michal
  • 4,952
  • 8
  • 30
  • 63
38
votes
4 answers

How to deal with relational data in Redux?

The app I'm creating has a lot of entities and relationships (database is relational). To get an idea, there're 25+ entities, with any type of relations between them (one-to-many, many-to-many). The app is React + Redux based. For getting data from…
Jordan Enev
  • 16,904
  • 3
  • 42
  • 67
30
votes
6 answers

Reselect - selector that invokes another selector?

I have a selector: const someSelector = createSelector( getUserIdsSelector, (ids) => ids.map((id) => yetAnotherSelector(store, id), ); // ^^^^^ (yetAnotherSelector expects 2 args) That…
Patrickkx
  • 1,740
  • 7
  • 31
  • 60
26
votes
4 answers

Is there a way to properly mock Reselect selectors for unit testing?

I'm having a pretty complex selectors structure in my project (some selectors may have up to 5 levels of nesting) so some of them are very hard to test with passing input state and I would like to mock input selectors instead. However I found that…
Eugene Tsakh
  • 2,777
  • 2
  • 14
  • 27
24
votes
3 answers

Is there any place for OOP in redux?

I've been using object-oriented programming practices for 25 years and trying to move toward functional programming for the last 5 years, but my mind always goes towards OOP when I'm trying to do something complex and, especially now that ES6…
Sigfried
  • 2,943
  • 3
  • 31
  • 43
23
votes
1 answer

How can I get ownProps using reselect on redux?

I want to create a selector with memoization using reselect based on some ownProps of mapStateToProps.
Sibelius Seraphini
  • 5,303
  • 9
  • 34
  • 55
20
votes
2 answers

How to use Reselect selectors inside a Redux reducer

My app already has a large collection of selectors used by the various container objects. These are great for accessing different parts of the state and make refactoring the state much easier. Now I want to use my selectors inside some of my reducer…
burtyish
  • 1,033
  • 2
  • 13
  • 27
19
votes
1 answer

How do you use `reselect` to memoize an array?

Suppose I have a redux store with this state structure: { items: { "id1" : { foo: "foo1", bar: "bar1" }, "id2": { foo: "foo2", bar: "bar2" } } } This store evolves by receiving full new values of…
phtrivier
  • 13,047
  • 6
  • 48
  • 79
14
votes
2 answers

How to use createSelector with parameter and Typescript?

I use redux-toolkit to generate selectors. I want to use them in my own custom reselect selectors with parameters. But I do not know how to type the return type of my selector? const selectOrganizationName = (id: string): ??? => createSelector( …
tomole
  • 927
  • 3
  • 12
  • 35
13
votes
3 answers

How to use reselect on a changing list, when the objects are the same?

I use reselect to get parts of my redux state. i have a list of objects in my state. One of my subselector for my create selector is a filter function of this list: state => state.list.filter(filterFunction) So i pass this to my…
bitrevolution
  • 437
  • 6
  • 16
12
votes
3 answers

Reselect - does it ever make sense to create a memorized selector which is just used to get part of the state?

I have a normal selector which is just used to get part of the state: export const getAllPosts = state => { return state.posts; }; If I use the reselect to wrap the selector: import { createSelector } from 'reselect'; export const allPosts =…
Jason Xu
  • 845
  • 8
  • 22
12
votes
3 answers

how to use selectors in redux app with TypeScript?

I try to use selectors from reselect library in my Redux app. my selectors file looks: import { createSelector } from 'reselect' const postsSelectors = state => state.global.posts.allPostse; export const getPosts = createSelector( […
SuperManEver
  • 2,263
  • 6
  • 28
  • 36
10
votes
1 answer

How does reselect createStructuredSelector work in Typescript?

I’m trying to understand how the reselect method createStructuredSelector works in Typescript. I see this pattern a lot: export interface SomeProps { readonly property1: string; readonly property2: boolean; readonly property3:…
d0nutz1
  • 417
  • 6
  • 19
9
votes
1 answer

useSelector and reselect , which one is performance beneficial

For memoization/performance consideration, using useSelector with ShallowEqual. Will there be some more benefits for performance optimization using "Reselect/createSelector" option ? Or both the options are same ? Will have the data as JSON array…
dsi
  • 3,199
  • 12
  • 59
  • 102
9
votes
1 answer

Use createSelector (or any memoized selector) with hooks without mapStateToProps

I want to create a memoized selector which will update automatically when the state in the redux store changes. I read about Reselect's createSelector here: https://redux.js.org/recipes/computing-derived-data I see that mapStateToProps is being used…
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
1
2 3
25 26