Files
simply_cpq/website/node_modules/@base-ui/utils/useRefWithInit.mjs
T
2026-08-07 21:39:30 +02:00

20 lines
519 B
JavaScript

'use client';
import * as React from 'react';
const UNINITIALIZED = {};
/**
* A React.useRef() that is initialized with a function. Note that it accepts an optional
* initialization argument, so the initialization function doesn't need to be an inline closure.
*
* @usage
* const ref = useRefWithInit(sortColumns, columns)
*/
export function useRefWithInit(init, initArg) {
const ref = React.useRef(UNINITIALIZED);
if (ref.current === UNINITIALIZED) {
ref.current = init(initArg);
}
return ref;
}