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
6
votes
1 answer

Reselect will not correctly memoize with multiple instances of the same component

I'm reading the documentation for Redux and got stuck with reselect. The code below creates a selector and the documentation says, if we want to use it in two VisibleTodoList components then it won't work correctly. import { createSelector } from…
Dávid Molnár
  • 10,673
  • 7
  • 30
  • 55
6
votes
1 answer

Using web worker inside redux selector

I have a state which contains some data, that I currently compute synchronously in a selector using reselect library. Since this is heavy computation, I thought about doing it in a web worker. Problem is the selector will then return an asynchronous…
yould
  • 63
  • 3
5
votes
2 answers

Reselect createSelector by id

I am using reselect lib in my React project. I've created Posts selector which works fine. Here's the code // selectors.ts const getPosts = (state: RootState) => state.posts.posts; export const getPostsSelector = createSelector(getPosts, (posts)…
Andrew Losseff
  • 333
  • 5
  • 18
5
votes
3 answers

Reselect - how to figure out which argument changed?

Selectors are efficient. A selector is not recomputed unless one of its arguments changes. I'm trying to debug a selector that is being called more often than expected. Is there a way to log why a particular selector was recomputed (i. e. which…
asliwinski
  • 1,662
  • 3
  • 21
  • 38
5
votes
0 answers

Is it possible to properly memoize reselect selectors when using denormalize?

I recently noticed that when using normalizr’s ‘denormalize’ function within a reselect selector, memoization was failing every time. This is down to having to pass the entire entities object to the selector as an argument, which i suppose is too…
Matt Wills
  • 676
  • 6
  • 11
5
votes
3 answers

"Reselect" VS "Memoize-One" with "React and Redux"

I'm trying to use some kind of memoization in my workflow with React, and I'm searching for the best and most importantly the "easiest" solution to integrate with my workflow that includes React and Redux. I came across many articles talking about…
Ruby
  • 2,207
  • 12
  • 42
  • 71
5
votes
1 answer

React & Reselect selector claims state is the same after update

I am implementing Reselect in my project and have a little confusion on how to properly use it. After following multiple tutorials and articles about how to use reselect, I have used same patterns and still somethings dont work as expected. My…
Kiper
  • 309
  • 3
  • 17
5
votes
2 answers

Conditionally composing a selector using reselect

export const mySelector = createSelector( [selectorA, selectorB], // but I want selectorB or selectorC to be chosen here using logic (foo, bar) => { // ... } ); I want to conditionally use selectorB or selectorC when creating…
Ben Aston
  • 53,718
  • 65
  • 205
  • 331
5
votes
2 answers

Why the reselect createSelector necessary in this @ngrx example?

What does the following code snippet do? It is taken from this file. export const getCollectionLoading = createSelector(getCollectionState, fromCollection.getLoading); The fromCollection.getLoading has only either true or false value, so can there…
wonderful world
  • 10,969
  • 20
  • 97
  • 194
5
votes
2 answers

React-redux reselect performance

I have a question regarding performance while using reselect in a react redux application. The Reselect library is used as a memoization layer to cache calculations that are made for performance, but what if you do not need any calculations/logic…
Alexg2195
  • 605
  • 7
  • 18
5
votes
3 answers

How to connect each element of array individually by using react redux

The current approach is to connect whole book list into Book List Component. However, it is not an efficient to render huge components by changing only several fields in state. I dont know how to map each book component connect to each individual…
Xiaohe Dong
  • 4,953
  • 6
  • 24
  • 53
5
votes
1 answer

ngrx/store selector returns function instead of object

I am following the example-app (https://github.com/ngrx/example-app), all my stores, effects, actions are working great but I am getting weird behaviour when using selector defined in the reducer file vs selector defined in the container file. The…
skuppa
  • 135
  • 9
5
votes
3 answers

When using redux with immutable-js - do you call toJS() on your selector? Or do you use .get('prop') in the render function?

Right now I'm using reselect to create my selectors to extract data from the store and pass it to the props via connect. For simplicity, the result of my selectors is always a JS object (calling toJS() at the end of the selector), something like…
Adam Tal
  • 5,911
  • 4
  • 29
  • 49
4
votes
1 answer

How to pass parameters to the result Function of a createSelector (reselect)

My redux store has two independent slices A and B, I need a memorized selector which returns something derived from B, only if A changes. For example const getSliceA = (state) => state.A export const getSliceB = createSelector( getSliceA, (a) =>…
Hiran
  • 698
  • 1
  • 10
  • 29
4
votes
0 answers

How to use Flow to type a generic reselect selector?

I have two types of similar, but distinct, structures: type A = { foo: string, bar: string, specialA: string }; type B = { foo: string, bar: string, specialB: string }; I am using reselect to create selectors, using the types from flow-typed here.…
EugeneZ
  • 1,615
  • 11
  • 17
1 2
3
25 26