diff --git a/docs/rfcs/data-loaders/colada.md b/docs/rfcs/data-loaders/colada.md index 7369b85ac..5d521545e 100644 --- a/docs/rfcs/data-loaders/colada.md +++ b/docs/rfcs/data-loaders/colada.md @@ -1 +1,83 @@ # `defineColadaLoader()` + +Loaders that use [@pinia/colada](https://github.com/posva/pinia-colada) under the hood. These loaders provide a more efficient way to have asynchronous state with cache, ssr support and more. + +```vue + + + + + +``` + +::: tip +Pass a route name to `defineColadaLoader` to get typed routes in the `query` function. + +```ts +export const useUserData = defineColadaLoader('/users/[id]', { + // ... +}) +``` + +::: + +## Refresh by default + +To avoid unnecesarry frequent refreshes, Pinia Colada refreshes the data when navigating (instead of _refetching_). Change the `staleTime` option to control how often the data should be refreshed, e.g. setting it to 0 will refresh the data every time the route changes. + +## Route tracking + +The `query` function tracks what is used in the `to` parameter and will only refresh the data if **tracked** properties change. This means that if you use `to.params.id` in the `query` function, it will only refetch the data if the `id` parameter changes but not if other properties like `to.query`, `to.hash` or even `to.params.other` change. diff --git a/playground/src/pages/users/colada-loader.[id].vue b/playground/src/pages/users/colada-loader.[id].vue index fbac631df..9e71708ab 100644 --- a/playground/src/pages/users/colada-loader.[id].vue +++ b/playground/src/pages/users/colada-loader.[id].vue @@ -56,10 +56,11 @@ function copy() { } const { - data: pcUSer, + // + data: user, status, - error: pcError, - isLoading: pcIsFetching, + error, + isLoading, reload, refresh, } = useUserData() @@ -95,9 +96,9 @@ const {

status: {{ status }}
- isFetching: {{ pcIsFetching }} + isFetching: {{ isLoading }}

-
Error: {{ pcError }}
-
{{ pcUSer == null ? String(pcUSer) : pcUSer }}
+
Error: {{ error }}
+
{{ user == null ? String(user) : user }}