parsec-hooks 1.0.10 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
- import { Dispatch, SetStateAction } from 'react';
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.useLayoutEffect)(function () {
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(globalState);
42
+ return fn(state);
41
43
  });
42
- globalObj[name].state = globalState;
43
- }, [globalState, name]);
44
- return [globalState, setGlobalState];
44
+ }, [name])];
45
45
  };
46
46
 
47
47
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "parsec-hooks",
3
- "version": "1.0.10",
3
+ "version": "1.0.13",
4
4
  "description": "秒差距前端常用的hooks工具",
5
5
  "author": "mushan0x0",
6
6
  "license": "MIT",