Open gusinacio opened 2 months ago
I am also interested in this, but I suspect the answer to your question may simply be to convert what you have above into a hook that can then be reused. I had a discussion about this with Evan (in the midst of many other topics): https://discord.com/channels/899851952891002890/1238219898795196499/1242814582746124328 and he suggested looking at https://dioxuslabs.com/learn/0.5/cookbook/state/custom_hooks for doing what you (and I) described.
It's worth noting that use_resource
already has some potentially relevant states: https://github.com/DioxusLabs/dioxus/blob/487570d89751b34bbfd5e9b5ff1e0fd3780bf332/packages/hooks/src/use_resource.rs#L132 and the difference is in the logic of how it automatically starts the async task immediately rather than waiting until some trigger.
Feature Request
I'd like to have a "use_resource" that allows me to trigger a query only when a button is pushed.
Currently, I'm using the following code to achieve this:
The problem with this approach is that I have to keep track of all the state information by myself. Also, it's hard to use in multiple places and I feel that this is a good feature for Dioxus