Feature Request: debounced selectors #2034
Replies: 1 comment 1 reply
-
Debouncing/throttling selector evaluations or component re-rendering is a fair request, but definitely not trivial. I wonder if a good idea might be to debounce within your |
Beta Was this translation helpful? Give feedback.
-
Hi! Thanks a lot for this library, it is an awesome breath of fresh air in React state management 🎉
I'm migrating a project to Recoil to see if it fits and there is a use case I've stumbled upon a few times and can't find a straightforward solution to it without adding useless boilerplate and escaping pure Recoil-style. In my use case it comes from async selectors.
Suppose I have something like this:
In some situations those five example params might change almost simultaneously, triggering five calls to
api.readData
where the first four are useless and only the fifth is the response we want. The one above is just a simple example but I'm finding myself in such situations more often than I would like to. 😢A simple solution would be to have a debounce parameter on selectors, so that we can just write:
And have this selector to only recompute it's get call 200 ms after it's dependencies are settled.
I would imagine the selector to enter a loading state as soon as it starts debouncing and then settle normally.
Right now I'm doing something dirty like the following, but it smells a lot:
Beta Was this translation helpful? Give feedback.
All reactions