@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.
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 把 emotion 的 css 函数注册为全局变量,就不用每次使用都手动引入了
3
+ */
4
+ import { css as cssValue } from '@emotion/react';
5
+ declare global {
6
+ var css: typeof cssValue;
7
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 把 emotion 的 css 函数注册为全局变量,就不用每次使用都手动引入了
3
+ */
4
+ import { css as cssValue } from '@emotion/react';
5
+ globalThis.css = cssValue;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 生成一个 state 以及与其值同步的 ref
3
+ */
4
+ export declare function useStateWithRef<T>(initialValue: T | (() => T)): readonly [T, (value: T | ((prevState: T) => T)) => void, import("react").RefObject<T>];
@@ -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.2",
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-prettier": "3.0.4",
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": {