@aiszlab/relax 1.2.69 → 1.2.70

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,17 +1,18 @@
1
1
  import { type Dispatch, type SetStateAction } from "react";
2
- import type { State } from "../types";
3
- interface Props<T> {
2
+ import type { State, RequiredTo } from "../types";
3
+ type UseControlledStateBy<T> = {
4
4
  /**
5
5
  * @description
6
6
  * default value
7
7
  */
8
8
  defaultState?: State<T>;
9
- }
9
+ };
10
+ type UsedControlledState<T, R> = R extends undefined ? [T, Dispatch<SetStateAction<T>>] : [RequiredTo<T>, Dispatch<SetStateAction<RequiredTo<T>>>];
10
11
  /**
11
12
  * @author murukal
12
13
  *
13
14
  * @description
14
15
  * controlled state
15
16
  */
16
- export declare const useControlledState: <T>(controlledState: T, { defaultState }?: Props<T>) => [T, Dispatch<SetStateAction<T>>];
17
+ export declare const useControlledState: <T, R extends T>(controlledState: T, { defaultState }?: UseControlledStateBy<R>) => UsedControlledState<T, R>;
17
18
  export {};
@@ -34,6 +34,7 @@ var useControlledState = function useControlledState(controlledState) {
34
34
  }, [controlledState]);
35
35
  /// use controlled
36
36
  var state = !isUndefined(controlledState) ? controlledState : _state;
37
+ // @ts-ignore
37
38
  return [state, _setState];
38
39
  };
39
40
 
@@ -7,3 +7,4 @@ export type { First } from "./first";
7
7
  export type { Last } from "./last";
8
8
  export type { State, StateGetter } from "./state";
9
9
  export type { Arrayable } from "./arrayable";
10
+ export type { RequiredTo } from "./required-to";
@@ -0,0 +1 @@
1
+ export type RequiredTo<T> = Exclude<T, undefined>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiszlab/relax",
3
- "version": "1.2.69",
3
+ "version": "1.2.70",
4
4
  "description": "react utils collection",
5
5
  "type": "module",
6
6
  "exports": {