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:
535 bytes
|
Line | |
---|
1 | import { useCallback, useRef, useState } from 'react';
|
---|
2 | export function useMediatedState(mediator, initialState) {
|
---|
3 | var mediatorFn = useRef(mediator);
|
---|
4 | var _a = useState(initialState), state = _a[0], setMediatedState = _a[1];
|
---|
5 | var setState = useCallback(function (newState) {
|
---|
6 | if (mediatorFn.current.length === 2) {
|
---|
7 | mediatorFn.current(newState, setMediatedState);
|
---|
8 | }
|
---|
9 | else {
|
---|
10 | setMediatedState(mediatorFn.current(newState));
|
---|
11 | }
|
---|
12 | }, [state]);
|
---|
13 | return [state, setState];
|
---|
14 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.