Replies: 2 comments 7 replies
-
@TkDodo @tannerlinsley any thoughts on this ? |
Beta Was this translation helpful? Give feedback.
-
@TkDodo So I suppose there's no way to use And for the scenario: when I click a button in a component, the component will need to fetch data either from the API or the cache if the key hasn't changed, I will need to send an event only once after the API finishes (whether with the new data or the cached one). Imagine this scenario with
Currently, there's a way to do this is to put the data of the I wonder if there's a way to do this? |
Beta Was this translation helpful? Give feedback.
-
Hello all,
While having a discussion with @TkDodo on twitter, we evoked the possibility to define lazy queries that can be fired from event handlers without relying on additional state variables in the developer land. ie:
For the library, it will just not run the fetcher and delay it until the decision comes from an event handler.
The difference between lazy and enabled is:
enabled
you put a condition that should work only whenlazy
is false, meaning at every dependency change, you check again if thecondition
in enabled is truthy and later you should keep track of enabled if it transition from false to true. And you can't change this condition unless to perform a complete render.lazy
you tell the library: Please don't fire automatically at all, the user will control this. It is similar to mutation, but mentally, it is a query that you can run from everywhere in your app and gives you data to display.For example, directly searching when the user types in drop down, or a search list that starts with empty results... and so on.
The
run
function then will pass its arguments asargs
property in theargv
that the query function receives.Here is a demonstration of what the API that I advice for:
Please note that I may contribute to the proposed features as well.
Best regards.
Beta Was this translation helpful? Give feedback.
All reactions