@anjianshi/utils 2.8.2 → 2.8.4
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 +4 -0
- package/env-react/hooks.js +16 -0
- package/env-react/index.d.ts +1 -0
- package/env-react/index.js +1 -0
- package/package.json +3 -3
- /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,16 @@
|
|
|
1
|
+
import { useRef, useCallback } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* 生成一个 state 以及与其值同步的 ref
|
|
4
|
+
*/
|
|
5
|
+
export function useStateWithRef(initialValue) {
|
|
6
|
+
const [state, setState] = useState(initialValue);
|
|
7
|
+
const ref = useRef(state);
|
|
8
|
+
const setStateWithRef = useCallback((value) => {
|
|
9
|
+
setState(prevState => {
|
|
10
|
+
const newValue = typeof value === 'function' ? value(prevState) : value;
|
|
11
|
+
ref.current = newValue;
|
|
12
|
+
return newValue;
|
|
13
|
+
});
|
|
14
|
+
}, []);
|
|
15
|
+
return [state, setStateWithRef, ref];
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hooks.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hooks.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anjianshi/utils",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.4",
|
|
4
4
|
"description": "Common JavaScript Utils",
|
|
5
5
|
"homepage": "https://github.com/anjianshi/js-packages/utils",
|
|
6
6
|
"bugs": {
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"typescript": "^5.8.3",
|
|
33
33
|
"vconsole": "^3.15.1",
|
|
34
34
|
"@anjianshi/presets-eslint-base": "6.0.0",
|
|
35
|
-
"@anjianshi/presets-eslint-node": "6.0.0",
|
|
36
35
|
"@anjianshi/presets-eslint-react": "6.0.0",
|
|
37
|
-
"@anjianshi/presets-
|
|
36
|
+
"@anjianshi/presets-eslint-node": "6.0.0",
|
|
38
37
|
"@anjianshi/presets-eslint-typescript": "6.0.0",
|
|
38
|
+
"@anjianshi/presets-prettier": "3.0.4",
|
|
39
39
|
"@anjianshi/presets-typescript": "3.2.4"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
File without changes
|
|
File without changes
|