UNPKG

@supunlakmal/hooks

Version:

A collection of reusable React hooks

15 lines 621 B
import { useMemo } from 'react'; /** * Custom hook that returns a default value if the provided value is null or undefined. * * @template T The type of the value. * @param value The potentially null or undefined value. * @param defaultValue The default value to return if `value` is null or undefined. * @returns The original value if it's not null/undefined, otherwise the default value. */ export function useDefault(value, defaultValue) { return useMemo(() => { return value !== null && value !== void 0 ? value : defaultValue; }, [value, defaultValue]); } //# sourceMappingURL=useDefault.js.map