useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.ts

usehooks-ts · packages/usehooks-ts/src/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.ts · typescript · MIT
ui

SSR-safe layout effect hook for React to prevent hydration mismatches.

// Source: https://github.com/juliencrn/usehooks-ts | License: MIT | Copyright 2020 Julien CARON
// Provided via justclaw.it.com; keep this notice with the code.
import { useEffect, useLayoutEffect } from 'react'

/**
 * Custom hook that uses either `useLayoutEffect` or `useEffect` based on the environment (client-side or server-side).
 * @param {Function} effect - The effect function to be executed.
 * @param {Array<any>} [dependencies] - An array of dependencies for the effect (optional).
 * @public
 * @see [Documentation](https://usehooks-ts.com/react-hook/use-isomorphic-layout-effect)
 * @example
 * ```tsx
 * useIsomorphicLayoutEffect(() => {
 *   // Code to be executed during the layout phase on the client side
 * }, [dependency1, dependency2]);
 * ```
 */
export const useIsomorphicLa

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key