@charlietango/use-client-hydrated
TypeScript icon, indicating that this package has built-in type declarations

1.10.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i @charlietango/use-client-hydrated

Weekly Downloads

4,788

Version

1.10.0

License

MIT

Unpacked Size

4.69 kB

Total Files

6

Last publish

Collaborators

  • thebuilder
  • frederik_bosch