Skip to content

Commit

Permalink
refactor: changes
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Nov 28, 2024
1 parent 986636a commit 1847d7d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/docs/ssr/nuxt.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,18 @@ await useAsyncData('user', () => store.fetchUser().then(() => true))

::: tip

If you want to use a store outside of `setup()`, remember to pass the `$pinia` instance to `useStore()`, for the reasons alluded to [here](https://pinia.vuejs.org/core-concepts/outside-component-usage.html#SSR-Apps).
If you want to use a store outside of `setup()` or an _injection aware_ context (e.g. Navigation guards, other stores, Nuxt Middlewares, etc), remember to pass the `pinia` instance to `useStore()`, for the reasons alluded to [here](https://pinia.vuejs.org/core-concepts/outside-component-usage.html#SSR-Apps). Retrieving the `pinia` instance might vary.

```js
```ts
import { useStore } from '~/stores/myStore'
const store = useStore(useNuxtApp().$pinia);

onMounted(() => {
if (window.innerWidth < 900) {
store.doAction()
}
});
// this line is usually inside a function that is able to retrieve
// the pinia instance
const store = useStore(pinia)
```

Fortunately, most of the time you **don't need to go through this hassle**.

:::

## Auto imports
Expand Down

0 comments on commit 1847d7d

Please sign in to comment.