use-is-hydrated
shadcn-hooks/use-is-hydratedFreeHook
A hook to check if the component is hydrated
Install it
npx shadcn@latest add https://shadcn-hooks.com/r/use-is-hydrated.jsonSource
1import { useSyncExternalStore } from 'react'23function subscribe() {4 return () => {}5}67/**8 * Return a boolean indicating if the JS has been hydrated already.9 * When doing Server-Side Rendering, the result will always be false.10 * When doing Client-Side Rendering, the result will always be false on the11 * first render and true from then on. Even if a new component renders it will12 * always start with true.13 *14 * Example: Disable a button that needs JS to work.15 * ```tsx16 * const isHydrated = useIsHydrated();17 * return (18 * <button type="button" disabled={!isHydrated} onClick={doSomethingCustom}>19 * Click me20 * </button>21 * );22 * ```23 */24export function useIsHydrated() {25 return useSyncExternalStore(26 subscribe,27 () => true,28 () => false,29 )30}
Files it writes
More from shadcn-hooks
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| use-active-elementuse-active-element | shadcn-hooks | Hooks | Free | no deps | |
| use-batteryuse-battery | shadcn-hooks | Hooks | Free | no deps | |
| use-booleanuse-boolean | shadcn-hooks | Hooks | Free | no deps | |
| use-click-any-whereuse-click-any-where | shadcn-hooks | Hooks | Free | no deps | |
| use-click-awayuse-click-away | shadcn-hooks | Hooks | Free | no deps | |
| use-clipboarduse-clipboard | shadcn-hooks | Hooks | Free | no deps | |
| use-controllable-valueuse-controllable-value | shadcn-hooks | Hooks | Free | 1 dep | |
| use-counteruse-counter | shadcn-hooks | Hooks | Free | no deps |
