useIsomorphicLayoutEffect
React hook for using layout effect in both client-side and server-side rendering.
Installation
npm install @mvdlei/hooks
Example
Usage
import React from "react";
import { useIsomorphicLayoutEffect } from "@mvdlei/hooks";
const MyComponent = () => {
useIsomorphicLayoutEffect(() => {
// Your layout effect logic here
console.log("Layout effect applied!");
}, []);
return <div>My Component</div>;
};
Reference
export const useIsomorphicLayoutEffect: typeof useLayoutEffect | typeof useEffect;
Parameters
effect
: Function containing the code for the effect.deps
: Optional array of dependencies.
Return Value
The return value is the same as useLayoutEffect
or useEffect
.