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
|
Rev | Line | |
---|
[d565449] | 1 | "use strict";
|
---|
| 2 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 3 | exports.useMediatedState = void 0;
|
---|
| 4 | var react_1 = require("react");
|
---|
| 5 | function 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 | }
|
---|
| 18 | exports.useMediatedState = useMediatedState;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.