useProvidedRefOrCreate
Datalayer Core / useProvidedRefOrCreate
Function: useProvidedRefOrCreate()
useProvidedRefOrCreate<
TRef
>(providedRef?
):RefObject
<TRef
>
Defined in: tech/datalayer/core/src/hooks/useRef.ts:17
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
.
Type Parameters
TRef
TRef
Parameters
providedRef?
RefObject
<TRef
>
The ref to use - if undefined, will use the ref from a call to React.useRef
Returns
RefObject
<TRef
>