@anjianshi/utils 2.8.2 → 2.8.3
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/env-react/emotion-register-globals.d.ts +7 -0
- package/env-react/emotion-register-globals.js +5 -0
- package/env-react/hooks.d.ts +8 -0
- package/env-react/hooks.js +17 -0
- package/env-react/index.d.ts +1 -0
- package/env-react/index.js +1 -0
- package/package.json +1 -1
- /package/env-react/{react-register-global.d.ts → react-register-globals.d.ts} +0 -0
- /package/env-react/{react-register-global.js → react-register-globals.js} +0 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 生成一个 ref,存储指定值并同步更新
|
|
3
|
+
*/
|
|
4
|
+
export declare function useRefOfValue<T>(value: T): import("react").RefObject<T>;
|
|
5
|
+
/**
|
|
6
|
+
* 在 useState() 基础上,额外返回一个与 state 值同步的 ref
|
|
7
|
+
*/
|
|
8
|
+
export declare function useStateWithRef<T>(initialValue: T | (() => T)): readonly [T, import("react").Dispatch<import("react").SetStateAction<T>>, import("react").RefObject<T>];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* 生成一个 ref,存储指定值并同步更新
|
|
4
|
+
*/
|
|
5
|
+
export function useRefOfValue(value) {
|
|
6
|
+
const ref = useRef(value);
|
|
7
|
+
ref.current = value;
|
|
8
|
+
return ref;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* 在 useState() 基础上,额外返回一个与 state 值同步的 ref
|
|
12
|
+
*/
|
|
13
|
+
export function useStateWithRef(initialValue) {
|
|
14
|
+
const [state, setState] = useState(initialValue);
|
|
15
|
+
const ref = useRefOfValue(state);
|
|
16
|
+
return [state, setState, ref];
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hooks.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hooks.js';
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|