source: imaps-frontend/node_modules/react-use/lib/useStateValidator.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: 931 bytes
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var react_1 = require("react");
4function useStateValidator(state, validator, initialState) {
5 if (initialState === void 0) { initialState = [undefined]; }
6 var validatorInner = react_1.useRef(validator);
7 var stateInner = react_1.useRef(state);
8 validatorInner.current = validator;
9 stateInner.current = state;
10 var _a = react_1.useState(initialState), validity = _a[0], setValidity = _a[1];
11 var validate = react_1.useCallback(function () {
12 if (validatorInner.current.length >= 2) {
13 validatorInner.current(stateInner.current, setValidity);
14 }
15 else {
16 setValidity(validatorInner.current(stateInner.current));
17 }
18 }, [setValidity]);
19 react_1.useEffect(function () {
20 validate();
21 }, [state]);
22 return [validity, validate];
23}
24exports.default = useStateValidator;
Note: See TracBrowser for help on using the repository browser.