npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@duannx/vue-client-only

v1.0.3

Published

[![npm](https://img.shields.io/npm/v/vue-client-only.svg)](https://www.npmjs.com/package/vue-client-only) [![license](https://img.shields.io/github/license/duannx/vue-client-only.svg)]()

Downloads

3,269

Readme

vue-client-only

npm license

What is vue-client-only?

This component helps you to render a component on the client side only. Only support Vue3

Installation

npm install --save @duannx/vue-client-only
or
yarn add @duannx/vue-client-only

Usage

import ClientOnly from '@duannx/vue-client-only'

<client-only>
    <some-component></some-component>
    This will be render only in the client
    <template #placeholder>
      This is the placeholder that will be render on SSR
    </template>
</client-only>

Placeholder

Use the placeholder slot to render something on SSR

<client-only>
    This will be render only in the client
    <template #placeholder>
      This is the placeholder that will be render on SSR
    </template>
</client-only>

Props

  • is-show: Boolean. Use this prop to control exactly when the component is rendered on the client. If you don't set this prop, the component will be rendered on the client only when the component is mounted.
<!-- The default slot will be shown only when isShow is set to true -->
<client-only :is-show="isShow">
    This will be render only in the client
    <template #placeholder>
      This is the placeholder that will be render on SSR
    </template>
</client-only>

When to use this component?

  • When a component can not run on the server side. Not really. You can just move the logic that can only run on the browser to the mounted hook. No need to use this component.
  • When you face the error: Hydration mismatch. NO. Please. This error is caused by the state of the component in the client is not matching with the state in the server or some incorrect HTML nesting tags. You need to find the root cause and fix it. You need to find the root cause and fix it. Overuse of this component will eliminate the benefit of SSR.
  • When you want to reduce the server workload. This component will defer the rendering of the component on the server side. So your server will run faster, have better server response time, and reduce document size that transfer to the client.
  • When you want want to defer the rendering of the component on the client side. The is-show prop will help you. Almost the time, the under-the-fold content is not useful when the page loads. So you can defer the rendering of all under-the-fold content till the page is loaded or the user interacts with the page. Example, this code delay the rendering of the content till the user click or scroll the page:
<script setup>
  import ClientOnly from '@duannx/vue-client-only'
  import { onMounted } from '@vue/runtime-core'
  const isShow = ref(false)
  onMounted(() => {
    ['keydown', 'click', 'touchstart', 'scroll'].forEach((type) => {
      addEventListener(type, () => {
        isShow.value = true
      }, { once: true, capture: true });
    })
  })
</script>
<template>
Some above the fold content ...
<ClientOnly :is-show="isShow">
  <p>This content is loaded after the user input</p>
  <template #placeholder>
    <p>Content placeholder. Click anywhere to show the main content...</p>
  </template>
</ClientOnly>
</template>

DEMO

This DEMO only has the client side. It shows how the component looks like in the client. Demo code

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

vue-client-only use SemVer for versioning.

License

This project is licensed under the MIT License - see the LICENSE file for details.