@aiszlab/relax 1.0.13 → 1.0.15

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.
package/dist/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export { useMount } from './use-mount';
5
5
  export { useMounted } from './use-mounted';
6
6
  export { useTimeout } from './use-timeout';
7
7
  export { useControlledState } from './use-controlled-state';
8
+ export { useOnceState } from './use-once-state';
package/dist/index.js CHANGED
@@ -5,3 +5,4 @@ export { useMount } from './use-mount.js';
5
5
  export { useMounted } from './use-mounted.js';
6
6
  export { useTimeout } from './use-timeout.js';
7
7
  export { useControlledState } from './use-controlled-state.js';
8
+ export { useOnceState } from './use-once-state.js';
@@ -10,7 +10,7 @@ const useBoolean = (initialValue) => {
10
10
  const [isOn, setIsOn] = useState(initialValue || false);
11
11
  const turnOn = useCallback(() => setIsOn(true), []);
12
12
  const turnOff = useCallback(() => setIsOn(false), []);
13
- const toggle = useCallback(() => setIsOn((prev) => !prev), []);
13
+ const toggle = useCallback(() => setIsOn((_isOn) => !_isOn), []);
14
14
  return {
15
15
  isOn,
16
16
  turnOn,
@@ -1,8 +1,8 @@
1
- /// <reference types="react" />
1
+ import { type Dispatch, type SetStateAction } from 'react';
2
2
  /**
3
3
  * @author murukal
4
4
  *
5
5
  * @description
6
6
  * controlled state
7
7
  */
8
- export declare const useControlledState: <T>(value: T) => (T | import("react").Dispatch<import("react").SetStateAction<T>>)[];
8
+ export declare const useControlledState: <T>(value: T) => [T, Dispatch<SetStateAction<T>>];
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @author murukal
3
+ * @description 监听浏览器 media 变化,控制状态
4
+ *
5
+ * media 规则 @media not|only mediatype and (mediafeature and|or|not mediafeature)
6
+ */
7
+ export declare const useMediaQuery: () => void;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @author murukal
3
+ *
4
+ * @description
5
+ * state always be same after first render
6
+ */
7
+ export declare const useOnceState: <T>(initialValue: T) => T;
@@ -0,0 +1,13 @@
1
+ import { useState } from 'react';
2
+
3
+ /**
4
+ * @author murukal
5
+ *
6
+ * @description
7
+ * state always be same after first render
8
+ */
9
+ const useOnceState = (initialValue) => {
10
+ return useState(() => initialValue)[0];
11
+ };
12
+
13
+ export { useOnceState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",