parsec-hooks 1.0.10 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
declare const _default: <D extends unknown>(name: string, initState?: D) => [D, Dispatch<SetStateAction<D>>];
|
1
|
+
declare const _default: <D extends unknown>(name: string, initState?: D) => [D, (state: D) => void];
|
3
2
|
/**
|
4
3
|
* 在每个需要的地方使用传入,得到一个全局的状态,如:
|
5
4
|
* const globalLoading = useGlobalState('globalLoading')
|
@@ -35,13 +35,13 @@ var _default = function _default(name, initState) {
|
|
35
35
|
(0, _react.useLayoutEffect)(function () {
|
36
36
|
globalObj[name].sets.push(setGlobalState);
|
37
37
|
}, [name]);
|
38
|
-
(0, _react.
|
38
|
+
return [globalState, (0, _react.useCallback)(function (state) {
|
39
|
+
globalObj[name].state = state;
|
40
|
+
setGlobalState(state);
|
39
41
|
globalObj[name].sets.forEach(function (fn) {
|
40
|
-
return fn(
|
42
|
+
return fn(state);
|
41
43
|
});
|
42
|
-
|
43
|
-
}, [globalState, name]);
|
44
|
-
return [globalState, setGlobalState];
|
44
|
+
}, [name])];
|
45
45
|
};
|
46
46
|
|
47
47
|
exports.default = _default;
|