diff --git a/docs/.vitepress/navigation.js b/docs/.vitepress/navigation.js index 1e43b9c48e..65792ffc37 100644 --- a/docs/.vitepress/navigation.js +++ b/docs/.vitepress/navigation.js @@ -72,6 +72,10 @@ export default { text: 'Composables', collapsed: true, items: [ + { + text: 'useBoosterHydrate', + link: '/composables/useBoosterHydrate' + }, { text: 'useBoosterFont', link: '/composables/useBoosterFont' }, { text: 'useBoosterCritical', diff --git a/docs/src/composables/useBoosterHydrate.md b/docs/src/composables/useBoosterHydrate.md new file mode 100644 index 0000000000..0d441e7a23 --- /dev/null +++ b/docs/src/composables/useBoosterHydrate.md @@ -0,0 +1,21 @@ +--- +title: useBoosterHydrate +--- + +# {{$frontmatter.title}} + +Compasable provides a function for wrapping components in order to control hydration. + +[Learn more about component import](/guide/usage#import-components). + +## Return + +Returns import wrapper function. + +## Example + +```js +const hydrate = useBoosterHydrate(); + +const component = hydrate(() => import('~/components/MyComponent.vue')); +``` diff --git a/docs/src/guide/usage.md b/docs/src/guide/usage.md index 4c002c3f4f..7ba35aff4c 100644 --- a/docs/src/guide/usage.md +++ b/docs/src/guide/usage.md @@ -42,12 +42,14 @@ Until now, components were imported either statically (`import component from '@ In the background, the module [`vue3-lazy-hydration`](https://github.com/freddy38510/vue3-lazy-hydration) inspired by `vue-lazy-hydration` from [Markus Oberlehner](https://github.com/maoberlehner/vue-lazy-hydration) is used in a standardised way. +[Learn more about `useBoosterHydrate`](/composables/useBoosterHydrate). + ````js -import boosterHydrate from '#booster/hydrate'; +const hydrate = useBoosterHydrate(); export default { components: { - Stage: boosterHydrate(() => import('@/components/organisms/Stage')), + Stage: hydrate(() => import('@/components/organisms/Stage')), } }; ```` @@ -55,7 +57,7 @@ export default { Whether a component is in the viewport or not is determined in the background by the intersection observer. If the initialisation is to take place earlier, e.g. when scrolling, this can be adjusted accordingly via the `rootMargin` option in the [nuxt.config](/guide/options#lazyoffset). ::: warning -Although the #booster/hydrate function can be used in any component, we recommend its explicit use only in pages and layout. Its use within components can be useful only in explicit special cases. Here we recommend the general use of static imports. +Although the `useBoosterHydrate` composable can be used in any component, we recommend its explicit use only in pages and layout. Its use within components can be useful only in explicit special cases. Here we recommend the general use of static imports. ::: ::: info diff --git a/playground/layouts/default.vue b/playground/layouts/default.vue index 42a4f8db9a..eafb84f474 100644 --- a/playground/layouts/default.vue +++ b/playground/layouts/default.vue @@ -11,13 +11,14 @@