"use strict";
"use client";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useValueAsRef = useValueAsRef;
const utils_external_1 = require("../../utils-external");
const useRefWithInit_1 = require("./useRefWithInit");
function useValueAsRef(value) {
    const latest = (0, useRefWithInit_1.useRefWithInit)(createLatestRef, value).current;
    latest.next = value; // eslint-disable-line react-hooks/immutability
    // eslint-disable-next-line react-hooks/exhaustive-deps
    (0, utils_external_1.useClientLayoutEffect)(latest.effect);
    return latest;
}
function createLatestRef(value) {
    const latest = {
        current: value,
        next: value,
        effect: () => {
            latest.current = latest.next;
        },
    };
    return latest;
}
//# sourceMappingURL=useValueAsRef.js.map