Reactivity with UseFetch
Hi i have a custom useFetch composable for fetching my data from an external API. In
/location
page, when the user arrive, a first fetch is made with filterOptions
(a reactive object that can have empty string at start), this page has a Filter
component that content filters of the page and update filterOptions object according to user preferences.
I want to remove empty key in filterOptions
when the request is been made without loosing reactivity(refetch when some of filterOptions
change).
I stuck on it. That's my files.
Thanks5 Replies
Hi @Ulrich. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Sorry @Ulrich, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
Some help ?
You posted your custom
$fetch
and useFetch
implementations. A snippet of using those in the Filters
component could help more. But as I currently understand your question, you can create a computed variable (for example, refinedFilterOptions
) that removes the empty values filterOptions
and any other logic you want and pass that to the useApi
composable. Whenver the value of refinedFilterOptions
changes it will trigger re-fetching because its reactive.That's what i done, but i want to send each key in params, when i destructure the computed object, it loose reactivity, how can i send each key seperately in request body without loosing reactivity ?
Try using
watch
in useApi
and pass filteredOptions
to it.