question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Selector function and variables inside are memoized

See original GitHub issue

Consider 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
RichardLindhoutcommented, Mar 8, 2021

Thank you for providing feedback. It works now! https://codesandbox.io/s/proud-platform-28s6d?file=/package.json

1reaction
dan-leecommented, Mar 11, 2021

Thank you so much for your quick action (and sorry for the headaches I might be causing 😅). Still enjoying your library a lot 🙌!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found