import { useRef } from "react";

export function useConstant<T>(init: () => T): T {
    const initialized = useRef(false);
    const ref = useRef<T>();
    if (!initialized.current) {
        initialized.current = true;
        ref.current = init();
    }
    return ref.current;
}
