import { useCallback, useState } from "react";

export const useCallbackRef = <T,>() => {
    const [ref, setRef] = useState<T | null>(null);
    const callbackRef = useCallback((instance: T | null) => {
        if (ref || !instance) return;
        setRef(instance);
    }, [ref]);

    return [ref, callbackRef] as const;
}
