@mitcsutt/kiln-forms
Version:
Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui
31 lines (30 loc) • 933 B
JavaScript
import { getFormRuntime as e, isInactive as t, useResolvedForm as n } from "../runtime/formRuntime.js";
import { pickErrors as r } from "../runtime/errors.js";
import { areErrorsVisible as i } from "../runtime/reveal.js";
import { useCallback as a, useSyncExternalStore as o } from "react";
//#region src/hooks/useScopeErrors.ts
function s(s, c) {
let l = n(c), u = e(l), d = a((e) => {
let t = l.store.subscribe(e), n = u.subscribe(e), r = s?.subscribe(e);
return () => {
t.unsubscribe(), n(), r?.();
};
}, [
l,
u,
s
]), f = () => {
let e = s?.names() ?? [];
if (e.length === 0) return 0;
let n = l.store.state, a = n.submissionAttempts > 0, o = n.fieldMeta, c = 0;
for (let n of e) {
let e = o[n];
e && !t(u, n) && r(e.errorMap).length !== 0 && i(u, e, a) && (c += 1);
}
return c;
};
return o(d, f, f);
}
//#endregion
export { s as useScopeErrors };
//# sourceMappingURL=useScopeErrors.js.map