react-when-ready
Version:
React tools for content readiness orchestration. Provides context providers, hooks and components to coordinate smooth transitions when async content becomes available
18 lines (17 loc) • 671 B
TypeScript
/**
* A modified version of `useLayoutEffect` that only triggers when a condition is met
* and (optionally) runs just once during the component's lifecycle.
*
* @param condition - Boolean flag that enables the effect
* @param effect - Callback function (same as in `useLayoutEffect`)
* @param isOnce - If `true`, the effect will fire only once (default: `true`)
*
* @example
* // Runs only when `isVisible=true` and only once
* useConditionalLayoutEffect(
* isVisible,
* () => console.log('Component became visible'),
* true
* );
*/
export declare const useConditionalLayoutEffect: (condition: boolean, effect: () => void, isOnce?: boolean) => void;