Socket
Book a DemoInstallSign in
Socket

@charlietango/use-client-hydrated

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@charlietango/use-client-hydrated

Check if the client has been hydrated

latest
Source
npmnpm
Version
1.10.0
Version published
Weekly downloads
2K
79.16%
Maintainers
2
Weekly downloads
 
Created
Source

useClientHydrated

Check if the client has been hydrated. This hook only informs you of the current hydration state, and doesn't trigger a new render once the client becomes hydrated. To check that, you'd combine it with a useEffect to trigger a new render.

Checkout the Storybook demo.

Installation

yarn add @charlietango/use-client-hydrated

API

const output = useClientHydrated()

Example

import React, { useEffect, useState } from 'react'
import useClientHydrated from '@charlietango/use-client-hydrated'

const Component = () => {
  const hydrated = useClientHydrated()

  // Set the initial ready state based on hydrated. Will be `false` first time the component is rendered, but true after hydration.
  const [ready, setReady] = useState(hydrated)

  useEffect(() => {
    // We have been hydrated correctly now
    setReady(true)
  }, [])

  return <div>{ready ? 'Hydrated' : 'Hydrating'}</div>
}

export default Component

Keywords

react

FAQs

Package last updated on 14 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts