Debouncing API requests #1143
-
Hello, thanks again for Leptos! I need to fetch data from an API. The fetching is done based on a bunch of user inputs. I don't want to have more than one request in flight at a given moment as to not flood the server. I also don't want the UI to be stale, so, if by the time the current API fetching is done, the user input has changed, I want to re-trigger the fetching. Currently I'm storing a reference of the resource using store_value and using it inside the resource fetcher (feels like a self reference, which is normally cursed in Rust :D, but works with Leptos due to the context magic ) . This feels a bit hacky and clunky. I wonder if there is a better alternative.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Agreed it seems clunky and we should have a better way. This seems to me to be similar to #1124 in the sense that "resources should just hold their latest value." I don't know that I have a better answer here, but we're certainly looking for some! |
Beta Was this translation helpful? Give feedback.
-
Hi! I love leptos! I was wondering along these lines too, on a system that would intelligently handle requests, caching, request debouncing... Have you looked into |
Beta Was this translation helpful? Give feedback.
Agreed it seems clunky and we should have a better way. This seems to me to be similar to #1124 in the sense that "resources should just hold their latest value." I don't know that I have a better answer here, but we're certainly looking for some!