@aiszlab/relax 1.0.18 → 1.0.19
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/hooks/use-controlled-state.d.ts +13 -0
- package/dist/{use-controlled-state.js → hooks/use-controlled-state.js} +11 -4
- package/dist/hooks/use-once-state.d.ts +8 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +8 -8
- package/dist/types/state.d.ts +8 -0
- package/dist/utils/state.d.ts +6 -0
- package/dist/utils/state.js +9 -0
- package/package.json +1 -1
- package/dist/use-controlled-state.d.ts +0 -12
- package/dist/use-once-state.d.ts +0 -7
- /package/dist/{use-boolean.d.ts → hooks/use-boolean.d.ts} +0 -0
- /package/dist/{use-boolean.js → hooks/use-boolean.js} +0 -0
- /package/dist/{use-debounce-callback.d.ts → hooks/use-debounce-callback.d.ts} +0 -0
- /package/dist/{use-debounce-callback.js → hooks/use-debounce-callback.js} +0 -0
- /package/dist/{use-image-loader.d.ts → hooks/use-image-loader.d.ts} +0 -0
- /package/dist/{use-image-loader.js → hooks/use-image-loader.js} +0 -0
- /package/dist/{use-media-query.d.ts → hooks/use-media-query.d.ts} +0 -0
- /package/dist/{use-mount.d.ts → hooks/use-mount.d.ts} +0 -0
- /package/dist/{use-mount.js → hooks/use-mount.js} +0 -0
- /package/dist/{use-mounted.d.ts → hooks/use-mounted.d.ts} +0 -0
- /package/dist/{use-mounted.js → hooks/use-mounted.js} +0 -0
- /package/dist/{use-once-state.js → hooks/use-once-state.js} +0 -0
- /package/dist/{use-timeout.d.ts → hooks/use-timeout.d.ts} +0 -0
- /package/dist/{use-timeout.js → hooks/use-timeout.js} +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Dispatch, type SetStateAction } from 'react';
|
|
2
|
+
import type { State } from '../types/state';
|
|
3
|
+
interface Props<T> {
|
|
4
|
+
defaultState?: State<T>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @author murukal
|
|
8
|
+
*
|
|
9
|
+
* @description
|
|
10
|
+
* controlled state
|
|
11
|
+
*/
|
|
12
|
+
export declare const useControlledState: <T>(controlledState: State<T>, props?: Props<T> | undefined) => [T, Dispatch<SetStateAction<T>>];
|
|
13
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react';
|
|
2
|
+
import { isFunction } from '../utils/state.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @author murukal
|
|
@@ -8,12 +9,18 @@ import { useState, useEffect } from 'react';
|
|
|
8
9
|
*/
|
|
9
10
|
const useControlledState = (controlledState, props) => {
|
|
10
11
|
const [state, setState] = useState(() => {
|
|
11
|
-
if (controlledState
|
|
12
|
-
return props === null || props === void 0 ? void 0 : props.defaultState;
|
|
13
|
-
}
|
|
14
|
-
if (typeof controlledState === 'function') {
|
|
12
|
+
if (isFunction(controlledState)) {
|
|
15
13
|
return controlledState();
|
|
16
14
|
}
|
|
15
|
+
if (controlledState === void 0) {
|
|
16
|
+
if ((props === null || props === void 0 ? void 0 : props.defaultState) === void 0) {
|
|
17
|
+
return controlledState;
|
|
18
|
+
}
|
|
19
|
+
if (isFunction(props.defaultState)) {
|
|
20
|
+
return props.defaultState();
|
|
21
|
+
}
|
|
22
|
+
return props.defaultState;
|
|
23
|
+
}
|
|
17
24
|
return controlledState;
|
|
18
25
|
});
|
|
19
26
|
useEffect(() => {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { useBoolean } from './use-boolean';
|
|
2
|
-
export { useDebounceCallback } from './use-debounce-callback';
|
|
3
|
-
export { useImageLoader } from './use-image-loader';
|
|
4
|
-
export { useMount } from './use-mount';
|
|
5
|
-
export { useMounted } from './use-mounted';
|
|
6
|
-
export { useTimeout } from './use-timeout';
|
|
7
|
-
export { useControlledState } from './use-controlled-state';
|
|
8
|
-
export { useOnceState } from './use-once-state';
|
|
1
|
+
export { useBoolean } from './hooks/use-boolean';
|
|
2
|
+
export { useDebounceCallback } from './hooks/use-debounce-callback';
|
|
3
|
+
export { useImageLoader } from './hooks/use-image-loader';
|
|
4
|
+
export { useMount } from './hooks/use-mount';
|
|
5
|
+
export { useMounted } from './hooks/use-mounted';
|
|
6
|
+
export { useTimeout } from './hooks/use-timeout';
|
|
7
|
+
export { useControlledState } from './hooks/use-controlled-state';
|
|
8
|
+
export { useOnceState } from './hooks/use-once-state';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { useBoolean } from './use-boolean.js';
|
|
2
|
-
export { useDebounceCallback } from './use-debounce-callback.js';
|
|
3
|
-
export { useImageLoader } from './use-image-loader.js';
|
|
4
|
-
export { useMount } from './use-mount.js';
|
|
5
|
-
export { useMounted } from './use-mounted.js';
|
|
6
|
-
export { useTimeout } from './use-timeout.js';
|
|
7
|
-
export { useControlledState } from './use-controlled-state.js';
|
|
8
|
-
export { useOnceState } from './use-once-state.js';
|
|
1
|
+
export { useBoolean } from './hooks/use-boolean.js';
|
|
2
|
+
export { useDebounceCallback } from './hooks/use-debounce-callback.js';
|
|
3
|
+
export { useImageLoader } from './hooks/use-image-loader.js';
|
|
4
|
+
export { useMount } from './hooks/use-mount.js';
|
|
5
|
+
export { useMounted } from './hooks/use-mounted.js';
|
|
6
|
+
export { useTimeout } from './hooks/use-timeout.js';
|
|
7
|
+
export { useControlledState } from './hooks/use-controlled-state.js';
|
|
8
|
+
export { useOnceState } from './hooks/use-once-state.js';
|
package/package.json
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type Dispatch, type SetStateAction } from 'react';
|
|
2
|
-
interface Props<T> {
|
|
3
|
-
defaultState: T;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* @author murukal
|
|
7
|
-
*
|
|
8
|
-
* @description
|
|
9
|
-
* controlled state
|
|
10
|
-
*/
|
|
11
|
-
export declare const useControlledState: <T>(controlledState?: T | (() => T) | undefined, props?: Props<T> | undefined) => [T | undefined, Dispatch<SetStateAction<T | undefined>>];
|
|
12
|
-
export {};
|
package/dist/use-once-state.d.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|