* esm * wip * wip * wip * wip * wip * wip * subscription notice * wip * wip * wip * fix envs * fix: update docker build * fix * esm/types * delete dashboard :D * add patches to dockerfiles * update packages + catalogs + ts * wip * remove native libs * ts * improvements * fix redirects and fetching session * try fix favicon * fixes * fix * order and resize reportds within a dashboard * improvements * wip * added userjot to dashboard * fix * add op * wip * different cache key * improve date picker * fix table * event details loading * redo onboarding completely * fix login * fix * fix * extend session, billing and improve bars * fix * reduce price on 10M
28 lines
724 B
TypeScript
28 lines
724 B
TypeScript
import * as React from 'react';
|
|
|
|
/**
|
|
* @see https://github.com/radix-ui/primitives/blob/main/packages/react/use-callback-ref/src/useCallbackRef.tsx
|
|
*/
|
|
|
|
/**
|
|
* A custom hook that converts a callback to a ref to avoid triggering re-renders when passed as a
|
|
* prop or avoid re-executing effects when passed as a dependency
|
|
*/
|
|
function useCallbackRef<T extends (...args: never[]) => unknown>(
|
|
callback: T | undefined,
|
|
): T {
|
|
const callbackRef = React.useRef(callback);
|
|
|
|
React.useEffect(() => {
|
|
callbackRef.current = callback;
|
|
});
|
|
|
|
// https://github.com/facebook/react/issues/19240
|
|
return React.useMemo(
|
|
() => ((...args) => callbackRef.current?.(...args)) as T,
|
|
[],
|
|
);
|
|
}
|
|
|
|
export { useCallbackRef };
|