Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit c3d2950

Browse files
committed
docs: add warning on usage of ssrRef in factory functions
1 parent 6a67c05 commit c3d2950

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/helpers/ssrRef.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,25 @@ const val2 = ssrRef(myExpensiveSetterFunction)
2424
::: tip
2525
Under the hood, `ssrRef` requires a key to ensure that the ref values match between client and server. If you have added `nuxt-composition-api` to your `buildModules`, this will be done automagically by an injected Babel plugin. If you need to do things differently, you can specify a key manually or add `nuxt-composition-api/babel` to your Babel plugins.
2626
:::
27+
28+
::: warning
29+
At the moment, an `ssrRef` is only suitable for one-offs, unless you provide your own unique key.
30+
31+
This is because server and client `ssrRef` matches up based on line number within your code.
32+
33+
```ts
34+
function useMyFeature() {
35+
// Only one unique key is generated
36+
const feature = ssrRef('')
37+
return feature
38+
}
39+
40+
const a = useMyFeature()
41+
const b = useMyFeature()
42+
43+
b.value = 'changed'
44+
// On client-side, a's value will also be initialised to 'changed'
45+
```
46+
47+
If you want to use this pattern, make sure to set a unique key based on each calling of the function.
48+
:::

0 commit comments

Comments
 (0)