@d-matrix/utils 1.25.0 → 1.26.0
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/file.js +2 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +1 -0
- package/dist/react/useIsFirstRender.d.ts +6 -0
- package/dist/react/useIsFirstRender.js +14 -0
- package/package.json +1 -1
- package/readme.md +4 -0
package/dist/file.js
CHANGED
|
@@ -109,6 +109,8 @@ export function download(source, fileName = '', target) {
|
|
|
109
109
|
link.target = target;
|
|
110
110
|
}
|
|
111
111
|
else {
|
|
112
|
+
// https://stackoverflow.com/questions/33909763/download-attribute-with-a-file-name-not-working
|
|
113
|
+
// download 只在同源 URL 或 blob:、data: 协议起作用, 如果下载不同源的oss文件,download属性无效
|
|
112
114
|
link.download = fileName;
|
|
113
115
|
}
|
|
114
116
|
link.href = source;
|
package/dist/react/index.d.ts
CHANGED
package/dist/react/index.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* 使用 useIsFirstRender 区分第一次和后续渲染
|
|
4
|
+
* useIsFirstRender 对于确定当前渲染是否是组件的第一个渲染很有用。当你想在初始渲染时有条件地执行某些逻辑或渲染特定组件时,这个钩子特别有价值,提供了一种有效的方法来区分第一次和后续渲染。
|
|
5
|
+
* @returns boolean true 表示第一次渲染,false 表示其他渲染
|
|
6
|
+
*/
|
|
7
|
+
export function useIsFirstRender() {
|
|
8
|
+
const renderRef = useRef(true);
|
|
9
|
+
if (renderRef.current === true) {
|
|
10
|
+
renderRef.current = false;
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return renderRef.current;
|
|
14
|
+
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -198,6 +198,10 @@ export default function Component() {
|
|
|
198
198
|
}
|
|
199
199
|
```
|
|
200
200
|
|
|
201
|
+
- `useIsFirstRender(): boolean`
|
|
202
|
+
|
|
203
|
+
对于确定当前渲染是否是组件的第一个渲染很有用。当你想在初始渲染时有条件地执行某些逻辑或渲染特定组件时,这个 hook 特别有价值,提供了一种有效的方法来区分第一次和后续渲染。
|
|
204
|
+
|
|
201
205
|
### dom
|
|
202
206
|
|
|
203
207
|
- `scrollToTop(element: Element | null | undefined): void`
|