@aiszlab/relax 1.0.22 → 1.0.24

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,13 +1,9 @@
1
1
  import { type Dispatch, type SetStateAction } from 'react';
2
2
  import { type State } from '../utils/is-state-getter';
3
- interface Props<T> {
4
- defaultState?: State<T>;
5
- }
6
3
  /**
7
4
  * @author murukal
8
5
  *
9
6
  * @description
10
7
  * controlled state
11
8
  */
12
- export declare const useControlledState: <T>(controlledState: State<T>, { defaultState }?: Props<T>) => [T, Dispatch<SetStateAction<T>>];
13
- export {};
9
+ export declare const useControlledState: <T>(controlledState: State<T>) => [T, Dispatch<SetStateAction<T>>];
@@ -1,6 +1,6 @@
1
1
  import { useState, useEffect } from 'react';
2
2
  import { isStateGetter } from '../utils/is-state-getter.js';
3
- import { isVoid } from '../utils/is-void.js';
3
+ import { isUndefined } from '../utils/is-undefined.js';
4
4
 
5
5
  /**
6
6
  * @author murukal
@@ -8,23 +8,19 @@ import { isVoid } from '../utils/is-void.js';
8
8
  * @description
9
9
  * controlled state
10
10
  */
11
- const useControlledState = (controlledState, { defaultState } = {}) => {
11
+ const useControlledState = (controlledState) => {
12
12
  /// initialize state
13
13
  const [state, setState] = useState(() => {
14
14
  if (isStateGetter(controlledState))
15
15
  return controlledState();
16
- if (isVoid(controlledState)) {
17
- if (isVoid(defaultState))
18
- return controlledState;
19
- if (isStateGetter(defaultState))
20
- return defaultState();
21
- return defaultState;
22
- }
23
16
  return controlledState;
24
17
  });
25
18
  useEffect(() => {
26
19
  // when state is not controlled
27
- if (isVoid(controlledState))
20
+ if (isUndefined(controlledState))
21
+ return;
22
+ // if input state is function, mean it is not controlled
23
+ if (isStateGetter(controlledState))
28
24
  return;
29
25
  // if state is equal with value
30
26
  if (controlledState === state)
package/dist/index.d.ts CHANGED
@@ -15,5 +15,7 @@ export { useOnceState } from './hooks/use-once-state';
15
15
  * utils
16
16
  */
17
17
  export { isRefable } from './utils/is-refable';
18
- export { isVoid } from './utils/is-void';
18
+ export { isUndefined } from './utils/is-undefined';
19
19
  export { isStateGetter } from './utils/is-state-getter';
20
+ export { isNull } from './utils/is-null';
21
+ export { isVoid } from './utils/is-void';
package/dist/index.js CHANGED
@@ -7,5 +7,7 @@ export { useTimeout } from './hooks/use-timeout.js';
7
7
  export { useControlledState } from './hooks/use-controlled-state.js';
8
8
  export { useOnceState } from './hooks/use-once-state.js';
9
9
  export { isRefable } from './utils/is-refable.js';
10
- export { isVoid } from './utils/is-void.js';
10
+ export { isUndefined } from './utils/is-undefined.js';
11
11
  export { isStateGetter } from './utils/is-state-getter.js';
12
+ export { isNull } from './utils/is-null.js';
13
+ export { isVoid } from './utils/is-void.js';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * is null
4
+ */
5
+ export declare const isNull: (value: unknown) => value is null;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * is null
4
+ */
5
+ const isNull = (value) => {
6
+ return value === null;
7
+ };
8
+
9
+ export { isNull };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @description
3
+ * is undefined
4
+ */
5
+ export declare const isUndefined: (value: unknown) => value is undefined;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @description
3
+ * is undefined
4
+ */
5
+ const isUndefined = (value) => {
6
+ return value === void 0;
7
+ };
8
+
9
+ export { isUndefined };
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * @description
3
- * is undefined
3
+ * is null or undefined
4
4
  */
5
- export declare const isVoid: (value: unknown) => value is undefined;
5
+ export declare const isVoid: (value: unknown) => value is null | undefined;
@@ -1,9 +1,12 @@
1
+ import { isUndefined } from './is-undefined.js';
2
+ import { isNull } from './is-null.js';
3
+
1
4
  /**
2
5
  * @description
3
- * is undefined
6
+ * is null or undefined
4
7
  */
5
8
  const isVoid = (value) => {
6
- return value === void 0;
9
+ return isNull(value) || isUndefined(value);
7
10
  };
8
11
 
9
12
  export { isVoid };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.0.22",
3
+ "version": "1.0.24",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",