source: imaps-frontend/node_modules/react-use/lib/useMultiStateValidator.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.1 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.useMultiStateValidator = void 0;
4var react_1 = require("react");
5function useMultiStateValidator(states, validator, initialValidity) {
6 if (initialValidity === void 0) { initialValidity = [undefined]; }
7 if (typeof states !== 'object') {
8 throw new Error('states expected to be an object or array, got ' + typeof states);
9 }
10 var validatorInner = react_1.useRef(validator);
11 var statesInner = react_1.useRef(states);
12 validatorInner.current = validator;
13 statesInner.current = states;
14 var _a = react_1.useState(initialValidity), validity = _a[0], setValidity = _a[1];
15 var validate = react_1.useCallback(function () {
16 if (validatorInner.current.length >= 2) {
17 validatorInner.current(statesInner.current, setValidity);
18 }
19 else {
20 setValidity(validatorInner.current(statesInner.current));
21 }
22 }, [setValidity]);
23 react_1.useEffect(function () {
24 validate();
25 }, Object.values(states));
26 return [validity, validate];
27}
28exports.useMultiStateValidator = useMultiStateValidator;
Note: See TracBrowser for help on using the repository browser.