UNPKG

@primer/react-brand

Version:

Primer Brand is a GitHub's design system for creating React-based marketing websites and digital experiences.

12 lines (11 loc) 869 B
import React from 'react'; /** * There are some situations where we only want to create a new ref if one is not provided to a component * or hook as a prop. However, due to the `rules-of-hooks`, we cannot conditionally make a call to `React.useRef` * only in the situations where the ref is not provided as a prop. * This hook aims to encapsulate that logic, so the consumer doesn't need to be concerned with violating `rules-of-hooks`. * @param providedRef The ref to use - can be a RefObject, RefCallback (functional ref), null or undefined. * @type TRef The type of the RefObject which should be created. * @returns A RefObject that either uses the provided ref, wraps a functional ref, or creates a new one */ export declare function useProvidedRefOrCreate<TRef>(providedRef?: React.RefObject<TRef> | React.RefCallback<TRef> | null): React.RefObject<TRef>;