Skip to content

Commit d1bb406

Browse files
committed
docs: fix template ref unwrapping examples in composable docs
- Update useBreakpoints and useHydration docs to show destructuring pattern - Add script .value usage examples alongside template auto-unwrapping - Update Reactivity tables to show actual types (ShallowRef) - Fix JSDoc example in useBreakpoints source Destructured refs are top-level in template context and auto-unwrap. Non-destructured access requires .value in templates.
1 parent 017aab4 commit d1bb406

File tree

3 files changed

+50
-28
lines changed

3 files changed

+50
-28
lines changed

apps/docs/src/pages/composables/plugins/use-breakpoints.md

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,31 +51,40 @@ app.mount('#app')
5151

5252
## Usage
5353

54-
Once the plugin is installed, use the `useBreakpoints` composable in any component:
54+
Once the plugin is installed, use the `useBreakpoints` composable in any component. Destructure the properties you need for automatic ref unwrapping in templates:
5555

5656
```vue UseBreakpoints
5757
<script setup lang="ts">
5858
import { useBreakpoints } from '@vuetify/v0'
5959
60-
const breakpoints = useBreakpoints()
60+
const { isMobile, mdAndUp, name, width, height } = useBreakpoints()
61+
62+
// In script, access .value
63+
if (isMobile.value) {
64+
console.log('Mobile detected')
65+
}
6166
</script>
6267
6368
<template>
6469
<div>
65-
<nav v-if="breakpoints.mdAndUp">
70+
<!-- Destructured refs auto-unwrap in templates -->
71+
<nav v-if="mdAndUp">
6672
<!-- Desktop navigation -->
6773
</nav>
6874
<nav v-else>
6975
<!-- Mobile navigation -->
7076
</nav>
7177
72-
<p v-if="breakpoints.isMobile">Mobile layout active</p>
73-
<p>Current breakpoint: {{ breakpoints.name }}</p>
74-
<p>Viewport: {{ breakpoints.width }} x {{ breakpoints.height }}</p>
78+
<p v-if="isMobile">Mobile layout active</p>
79+
<p>Current breakpoint: {{ name }}</p>
80+
<p>Viewport: {{ width }} x {{ height }}</p>
7581
</div>
7682
</template>
7783
```
7884

85+
> [!TIP]
86+
> When using the composable without destructuring, access `.value` in templates: `v-if="breakpoints.isMobile.value"`. Destructuring to top-level variables enables Vue's automatic ref unwrapping.
87+
7988
## Architecture
8089

8190
`useBreakpoints` uses the plugin pattern with viewport observation:
@@ -93,17 +102,17 @@ flowchart LR
93102

94103
## Reactivity
95104

96-
All breakpoint properties are reactive and automatically update when the viewport size changes.
97-
98-
| Property | Reactive | Notes |
99-
| - | :-: | - |
100-
| `name` | <AppSuccessIcon /> | Current breakpoint name |
101-
| `width` | <AppSuccessIcon /> | Viewport width in pixels |
102-
| `height` | <AppSuccessIcon /> | Viewport height in pixels |
103-
| `isMobile` | <AppSuccessIcon /> | Below mobile breakpoint threshold |
104-
| `xs` / `sm` / `md` / `lg` / `xl` / `xxl` | <AppSuccessIcon /> | Exact breakpoint matches |
105-
| `smAndUp` / `mdAndUp` / `lgAndUp` / `xlAndUp` / `xxlAndUp` | <AppSuccessIcon /> | At or above breakpoint |
106-
| `smAndDown` / `mdAndDown` / `lgAndDown` / `xlAndDown` / `xxlAndDown` | <AppSuccessIcon /> | At or below breakpoint |
107-
| `breakpoints` | <AppErrorIcon /> | Static config object |
105+
All breakpoint properties are `Readonly<ShallowRef>` and automatically update when the viewport size changes. Use `.value` in script; destructure for template auto-unwrapping.
106+
107+
| Property | Type | Notes |
108+
| - | - | - |
109+
| `name` | `ShallowRef<BreakpointName>` | Current breakpoint name |
110+
| `width` | `ShallowRef<number>` | Viewport width in pixels |
111+
| `height` | `ShallowRef<number>` | Viewport height in pixels |
112+
| `isMobile` | `ShallowRef<boolean>` | Below mobile breakpoint threshold |
113+
| `xs` / `sm` / `md` / `lg` / `xl` / `xxl` | `ShallowRef<boolean>` | Exact breakpoint matches |
114+
| `smAndUp` / `mdAndUp` / etc. | `ShallowRef<boolean>` | At or above breakpoint |
115+
| `smAndDown` / `mdAndDown` / etc. | `ShallowRef<boolean>` | At or below breakpoint |
116+
| `breakpoints` | `Record<string, number>` | Static config object (not reactive) |
108117

109118
<DocsApi />

apps/docs/src/pages/composables/plugins/use-hydration.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,24 @@ app.mount('#app')
4040

4141
## Usage
4242

43-
Once the plugin is installed, use the `useHydration` composable in any component:
43+
Once the plugin is installed, use the `useHydration` composable in any component. Destructure the properties for automatic ref unwrapping in templates:
4444

4545
```vue UseHydration
4646
<script setup lang="ts">
4747
import { useHydration } from '@vuetify/v0'
4848
49-
const hydration = useHydration()
49+
const { isHydrated, isSettled } = useHydration()
50+
51+
// In script, access .value
52+
if (isHydrated.value) {
53+
console.log('Hydration complete')
54+
}
5055
</script>
5156
5257
<template>
5358
<div>
54-
<p v-if="hydration.isHydrated.value">
59+
<!-- Destructured refs auto-unwrap in templates -->
60+
<p v-if="isHydrated">
5561
Application is hydrated - browser features available
5662
</p>
5763
<p v-else>
@@ -75,11 +81,11 @@ flowchart LR
7581

7682
## Reactivity
7783

78-
Hydration state is reactive and updates when the root component mounts.
84+
All properties are `Readonly<ShallowRef>` and update when the root component mounts. Use `.value` in script; destructure for template auto-unwrapping.
7985

80-
| Property | Reactive | Notes |
81-
| - | :-: | - |
82-
| `isHydrated` | <AppSuccessIcon /> | True after root component mounts |
83-
| `isSettled` | <AppSuccessIcon /> | True after next tick post-hydration |
86+
| Property | Type | Notes |
87+
| - | - | - |
88+
| `isHydrated` | `ShallowRef<boolean>` | True after root component mounts |
89+
| `isSettled` | `ShallowRef<boolean>` | True after next tick post-hydration |
8490

8591
<DocsApi />

packages/0/src/composables/useBreakpoints/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,20 @@ export function createBreakpointsPlugin<
331331
* <script setup lang="ts">
332332
* import { useBreakpoints } from '@vuetify/v0'
333333
*
334+
* // Destructure for template auto-unwrapping
334335
* const { isMobile, mdAndUp } = useBreakpoints()
336+
*
337+
* // In script, use .value
338+
* if (isMobile.value) {
339+
* console.log('Mobile detected')
340+
* }
335341
* </script>
336342
*
337343
* <template>
338344
* <div class="pa-4">
339-
* <p v-if="isMobile.value">Mobile layout active</p>
340-
* <p v-else-if="mdAndUp.value">Medium and up layout active</p>
345+
* <!-- Destructured refs auto-unwrap in templates -->
346+
* <p v-if="isMobile">Mobile layout active</p>
347+
* <p v-else-if="mdAndUp">Medium and up layout active</p>
341348
* </div>
342349
* </template>
343350
* ```

0 commit comments

Comments
 (0)