@aiszlab/relax 1.0.23 → 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>>];
@@ -8,24 +8,20 @@ import { isUndefined } from '../utils/is-undefined.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 (isUndefined(controlledState)) {
17
- if (isUndefined(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
20
  if (isUndefined(controlledState))
28
21
  return;
22
+ // if input state is function, mean it is not controlled
23
+ if (isStateGetter(controlledState))
24
+ return;
29
25
  // if state is equal with value
30
26
  if (controlledState === state)
31
27
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",