UNPKG

@bytedance/mona-client-web

Version:

web for mona

17 lines 722 B
import { useContext, useEffect, useRef } from "react"; import { FormContext } from './index'; export var useFormContext = function (name, value, reset) { var context = useContext(FormContext); var orderRef = useRef(null); useEffect(function () { if (context) { var index_1 = orderRef.current; orderRef.current = context.register(function () { return ({ name: name, value: typeof value === 'function' ? value() : value }); }, function () { return reset(); }, index_1); return function () { context.unregister(index_1); }; } return function () { }; }, [context, name, value, reset]); }; //# sourceMappingURL=hooks.js.map