Skip to content

Recoil - async data queries, add to an array instead of overwriting #2136

Answered by drarmstr
MarcDAFrame asked this question in Q&A
Discussion options

You must be logged in to vote

Async selectors are probably not the best way to model a stateful paginated cache like this as selectors value should just be a function of the current state/inputs, not on previously loaded state. One option might be to use an atom for the cache of loaded cases and then update that using an updater form (with callback). You could subscribe to changes in the pageAtom with an atom effect, though atom effects don't currently have a way to update other atoms so would be easier to do it from a React component. Though, you might be able to use useRecoilTransaction() or useRecoilCallback() there if you really want to avoid doing this in a component.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by MarcDAFrame
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants