@aiszlab/relax 1.2.11-beta.8 → 1.2.11-beta.9

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.
@@ -0,0 +1,8 @@
1
+ import { type State } from '../is/is-state-getter';
2
+ /**
3
+ * @author murukal
4
+ *
5
+ * @description
6
+ * state always be same after first render
7
+ */
8
+ export declare const useDefault: <T>(initialState: State<T>) => T;
@@ -0,0 +1,21 @@
1
+ import { useMemo } from 'react';
2
+ import { isStateGetter } from '../is/is-state-getter.js';
3
+
4
+ /**
5
+ * @author murukal
6
+ *
7
+ * @description
8
+ * state always be same after first render
9
+ */
10
+ const useDefault = (initialState) => {
11
+ return useMemo(() => {
12
+ if (isStateGetter(initialState)) {
13
+ return initialState();
14
+ }
15
+ else {
16
+ return initialState;
17
+ }
18
+ }, []);
19
+ };
20
+
21
+ export { useDefault };
package/dist/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export { useMount } from './hooks/use-mount';
9
9
  export { useMounted } from './hooks/use-mounted';
10
10
  export { useTimeout } from './hooks/use-timeout';
11
11
  export { useControlledState } from './hooks/use-controlled-state';
12
- export { useOnceState } from './hooks/use-once-state';
12
+ export { useDefault } from './hooks/use-default';
13
13
  export { useScrollLocker } from './hooks/use-scroll-locker';
14
14
  export { useForceUpdate } from './hooks/use-force-update';
15
15
  export { useScrollable } from './hooks/use-scrollable';
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ export { useMount } from './hooks/use-mount.js';
5
5
  export { useMounted } from './hooks/use-mounted.js';
6
6
  export { useTimeout } from './hooks/use-timeout.js';
7
7
  export { useControlledState } from './hooks/use-controlled-state.js';
8
- export { useOnceState } from './hooks/use-once-state.js';
8
+ export { useDefault } from './hooks/use-default.js';
9
9
  export { useScrollLocker } from './hooks/use-scroll-locker.js';
10
10
  export { useForceUpdate } from './hooks/use-force-update.js';
11
11
  export { useScrollable } from './hooks/use-scrollable.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.2.11-beta.8",
3
+ "version": "1.2.11-beta.9",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,8 +0,0 @@
1
- import type { State } from '../is/is-state-getter';
2
- /**
3
- * @author murukal
4
- *
5
- * @description
6
- * state always be same after first render
7
- */
8
- export declare const useOnceState: <T>(initialState: State<T>) => T;
@@ -1,13 +0,0 @@
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 = (initialState) => {
10
- return useState(initialState)[0];
11
- };
12
-
13
- export { useOnceState };