re-reselect | Enhance Reselect selectors with deeper memoization | Caching library
kandi X-RAY | re-reselect Summary
kandi X-RAY | re-reselect Summary
re-reselect is a lightweight wrapper around Reselect meant to enhance selectors with deeper memoization and cache management. Switching between different arguments using standard reselect selectors causes cache invalidation since default reselect cache has a limit of one. re-reselect forwards different calls to different reselect selectors stored in cache, so that computed/memoized values are retained. re-reselect selectors work as normal reselect selectors but they are able to determine when creating a new selector or querying a cached one on the fly, depending on the supplied arguments.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of re-reselect
re-reselect Key Features
re-reselect Examples and Code Snippets
Community Discussions
Trending Discussions on re-reselect
QUESTION
I have a React / Redux app that renders a grid of PureComponents. I want the components to only re-render when a prop value has changed, but in fact all components re-render on any update to store. The issue appears to be caused by an array property.
I've reproduced the issue in this sandbox. In this minimal example, two instances of the Cell component are rendered. Each displays a value that is separately recorded in the store, and can be incremented or decremented separately with a button.
Cell.js
...ANSWER
Answered 2020-Jan-08 at 10:48You are creating a new array on every mapStateToProps call with myArray: [0, 1, 2]
.
Because of this, mapStateToProps always returns an object with a new instance of an array.
Redux than does a shallow comparison of the previous props. The references of myArray changed, since oyu created a new one during the call and all cells get udpated. By removing the myArray: [0, 1, 2]
line, it works as expected. Move that array into redux, so that you do not generate a new one of every call.
The pure component is also useless, since redux already does a prop comparison and the pure component does the same thing again, so that is wasted since it always has the same result for redux and the pure component and is just more work.
Update: You are still creating a new array on every mapSateToPropsCall with the map function in getMyArray, since map returns a new array. Why do you not make the array static or memoize that, so that you only generate a new one, if needed?
Why do you not change how you save the data so that state.myArray[index]
returns the needed array?
And you still can transform the PureCompoennt to Component.
QUESTION
I have a React / Redux app in which I draw a 2-dimensional grid. The grid data is in the Redux store, as an array of arrays. e.g. for a 3x2 grid it might be like this:
...ANSWER
Answered 2020-Jan-07 at 20:51I think you missunderstand the mapStateToProps function. It will be called for every redux state update and it has to figure out, if the values for that changed. So it has to call every mapStateToProps for each cell.
That does not mean, though, that it rerenders that component. If the previous and current return values of mapStateToProps are the same, the update will be aborted.
So it is correct that the mapStateToProps is called. Check if the cells are actually rerendered. You can also remove the getValueCached wrapper and access the grid directly with state.grid[identifiers[0]][identifiers[1]]
. This will be faster than the cached version since its just a direct access. And you do not get any benefit from the cached version, since its not a heavy computation.
It might even be faster to connect the highest component and jsut let it rerender if needed. Another option is to use react-window to only render the current visible grid items, which will greatly improve your performance.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install re-reselect
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page