main
Last change
on this file since d565449 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";
|
---|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
3 | var react_1 = require("react");
|
---|
4 | function 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 | }
|
---|
24 | exports.default = useStateValidator;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.