Skip to content

Commit 275c2cd

Browse files
committed
docs: add addendum on useId usage with computed
1 parent a3c31de commit 275c2cd

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/api/composition-api-helpers.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ This is the underlying helper that powers [`defineModel()`](/api/sfc-script-setu
4242
set?: (v: T) => any
4343
}
4444
45-
type ModelRef<T, M extends PropertyKey = string, G = T, S = T> = Ref<G, S> & [
46-
ModelRef<T, M, G, S>,
47-
Record<M, true | undefined>
48-
]
45+
type ModelRef<T, M extends PropertyKey = string, G = T, S = T> = Ref<
46+
G,
47+
S
48+
> &
49+
[ModelRef<T, M, G, S>, Record<M, true | undefined>]
4950
```
5051

5152
- **Example**
@@ -132,3 +133,18 @@ Used to generate unique-per-application IDs for accessibility attributes or form
132133
IDs generated by `useId()` are also guaranteed to be stable across the server and client renders, so they can be used in SSR applications without leading to hydration mismatches.
133134

134135
If you have more than one Vue application instance of the same page, you can avoid ID conflicts by giving each app an ID prefix via [`app.config.idPrefix`](/api/application#app-config-idprefix).
136+
137+
:::warning Caution
138+
`useId()` should be not be called inside a `computed()` property as it may cause instance conflicts. Instead, declare the ID outside of `computed()` and reference it within the computed function.
139+
140+
```vue
141+
<script setup>
142+
import { computed, useId } from 'vue'
143+
144+
const id = useId()
145+
146+
const ariaDescribedBy = computed(() => `${id}-description`)
147+
</script>
148+
```
149+
150+
:::

0 commit comments

Comments
 (0)