]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: update nuxt docs to recommend callOnce (#2916)
authorAlexander Lichter <github@lichter.io>
Fri, 21 Feb 2025 16:42:59 +0000 (17:42 +0100)
committerEduardo San Martin Morote <posva13@gmail.com>
Sat, 1 Mar 2025 11:55:24 +0000 (12:55 +0100)
packages/docs/ssr/nuxt.md

index 2bcbf00796db869911c34a66dea559ee0f303356..2a78d672310f25e57019d69fe914633d09672804 100644 (file)
@@ -43,22 +43,23 @@ And that's it, use your store as usual!
 
 ## Awaiting for actions in pages
 
-As with `onServerPrefetch()`, you can call a store action within `asyncData()`. Given how `useAsyncData()` works, **make sure to return a value**. This will allow Nuxt to skip running the action on the client side and reuse the value from the server.
+As with `onServerPrefetch()`, you can call a store action within the `callOnce()` composable.
+This will allow Nuxt to run the action only once and avoids refetching data that is already present.
 
 ```vue{3-4}
 <script setup>
 const store = useStore()
 // we could also extract the data, but it's already present in the store
-await useAsyncData('user', () => store.fetchUser())
+await callOnce('user', () => store.fetchUser())
 </script>
 ```
 
-If your action doesn't resolve a value, you can add any non nullish value:
+Depending on your requirements, you can choose to run the action only once on the client, or on every navigation (which is closer to data fetching behavior of `useFetch()`/`useAsyncData()`)
 
 ```vue{3}
 <script setup>
 const store = useStore()
-await useAsyncData('user', () => store.fetchUser().then(() => true))
+await callOnce('user', () => store.fetchUser(), { mode: 'navigation' })
 </script>
 ```