Selector function and variables inside are memoized
See original GitHub issueConsider the following example: https://codesandbox.io/s/jolly-archimedes-hooy6
It looks like the very first selector callback is memoized and outside value changes are not considered.
I think this is a similar problem as useEffect, useCallback are having, that’s why they introduced the dependency array. I think react-ridge-state would also need a dependency array to make it work.
Like so
const content = pages.useSelector((state) => {
return state[page]
}, [page])
Either that, or it would be necessary to not memoize the selector func and put the responsibility into userland and suggest to use useCallback:
const content = pages.useSelector(useCallback((state) => state[page], [page]))
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Deriving Data with Selectors - Redux
Selector functions are typically defined in two different parts of a Redux ... to create memoized selectors that look up nested values:.
Read more >How can I memoize a variable derived from redux useSelector?
Memoized Selectors The best place to fix this is by using createSelector to create a memoized selector. For example: import {createSelector} ...
Read more >How to use Memoize to cache JavaScript function results and ...
The memoized function is caching the values of previous factorials which significantly improves calculations since they can be reused factorial( ...
Read more >Redux Selector - Medium
Selectors are convenience functions used for looking up and retrieving snippets of data from the Redux store, into your components.
Read more >Memoization in JavaScript, Angular and React | DotNetCurry
The array used for cache (variable memoizedKeyValues) is local to each instance of the function. Hence, we have separate function objects and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thank you for providing feedback. It works now! https://codesandbox.io/s/proud-platform-28s6d?file=/package.json
Thank you so much for your quick action (and sorry for the headaches I might be causing 😅). Still enjoying your library a lot 🙌!