"use client";
import { useClientLayoutEffect } from "../../utils-external/index.js";
import { useRefWithInit } from "./useRefWithInit.js";
function useValueAsRef(value) {
    const latest = useRefWithInit(createLatestRef, value).current;
    latest.next = value; // eslint-disable-line react-hooks/immutability
    // eslint-disable-next-line react-hooks/exhaustive-deps
    useClientLayoutEffect(latest.effect);
    return latest;
}
function createLatestRef(value) {
    const latest = {
        current: value,
        next: value,
        effect: () => {
            latest.current = latest.next;
        },
    };
    return latest;
}
export { useValueAsRef };
//# sourceMappingURL=useValueAsRef.js.map