Replies: 1 comment 2 replies
-
|
Hey @joprice inline selectors are a beast 'cause of how React makes us do things for concurrent/strict mode. Can you fill me in on a few details:
Your first example is supposed to work. That said, it is a best practice to make selectors stable references wherever possible due to:
We actually don't use export function useAtomSelectorMemo<T>(
selector: SelectorTemplate<T, []>, // `AtomSelectorOrConfig` in v1
deps: DependencyList = []
) {
return useAtomSelector(useMemo(() => selector, deps));
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have many atom selectors like the following:
I noticed that react was not getting updates, even though the selector was running correctly on each change to the player offsets atom. I realized that I didn't parameterize the selector, so I rewrote it to
After that, things worked perfectly. The solution makes sense to me, but I'm not sure I understand why. I would have expected in the original version to work, but not be correct in the sense that the results are being collapsed, as the id is not being taken into account. Maybe it's the inline selector that was the issue, but I saw many tests with inline selectors (and I have a few of them in my codebase, but perhaps they have similar issues). Should the selector provided to
useAtomSelectoralways be a stable reference?Beta Was this translation helpful? Give feedback.
All reactions