posva / pinia-colada

🍹 The smart data fetching layer for Pinia
https://pinia-colada.esm.dev/
MIT License
584 stars 7 forks source link

add `useQueryState()` #23

Open posva opened 3 months ago

posva commented 3 months ago

Allows retrieving the query state by key

Same questions for useMutationState()

ElisePatrikainen commented 2 months ago

To temporary reply to the questions (which of course can completely be improved, this is rather a first step), in the PR I have just opened (in draft):

Also, I am wondering if the composable should be called useQueryState (singular) or useQueriesState (plural), since it can handle the aggregation of several queries? Or an alternative could be provide two composables (useQueryState and useQueriesState).

posva commented 1 month ago

I think returning the aggregation is fine. But I think that useMutationsState() is more important than useQueryState(). In fact, I'm not sure about the usefulness of useQueriesState() without all of the options as it could start in an incoherent state (no initial data). So I think we should probably just add the mutation's one first and leave this for later

ElisePatrikainen commented 2 weeks ago

I am thinking about a use case for useQueryState: allowing accessing the cache of a query without reactivating it. That could be useful in the case of optimistic updates (to access and mutate the cache without potentially triggering a new call). What do you think about that?