Skip to content

Commit 0311c3b

Browse files
committed
doc : add code example
1 parent adbcbd7 commit 0311c3b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

documentation/docs/02-runes/05-$props.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,17 @@ Adding types is recommended, as it ensures that people using your component can
206206
This rune, added in version 5.20.0, generates an ID that is unique to the current component instance. When hydrating a server-rendered a component, the value will be consistent between server and client.
207207

208208
This is useful for linking elements via attributes like `for` and `aria-labelledby`.
209+
210+
```svelte
211+
<script>
212+
const uid = $props.id();
213+
</script>
214+
215+
<form>
216+
<label for="{uid}-firstname">First Name: </label>
217+
<input id="{uid}-firstname" type="text" />
218+
219+
<label for="{uid}-lastname">Last Name: </label>
220+
<input id="{uid}-lastname" type="text" />
221+
</form>
222+
```

0 commit comments

Comments
 (0)