source: imaps-frontend/node_modules/react-use/lib/useMediatedState.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: 686 bytes
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.useMediatedState = void 0;
4var react_1 = require("react");
5function useMediatedState(mediator, initialState) {
6 var mediatorFn = react_1.useRef(mediator);
7 var _a = react_1.useState(initialState), state = _a[0], setMediatedState = _a[1];
8 var setState = react_1.useCallback(function (newState) {
9 if (mediatorFn.current.length === 2) {
10 mediatorFn.current(newState, setMediatedState);
11 }
12 else {
13 setMediatedState(mediatorFn.current(newState));
14 }
15 }, [state]);
16 return [state, setState];
17}
18exports.useMediatedState = useMediatedState;
Note: See TracBrowser for help on using the repository browser.