@vnejs/uis.react.use-is-render-hook 0.1.2 → 0.1.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/package.json CHANGED
@@ -1,32 +1,26 @@
1
1
  {
2
2
  "name": "@vnejs/uis.react.use-is-render-hook",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {
7
- "build": "node ../../scripts/build-package.mjs",
8
- "publish:major:plugin": "npm run publish:major",
9
- "publish:minor:plugin": "npm run publish:minor",
10
- "publish:patch:plugin": "npm run publish:patch",
11
- "publish:major": "npm run build && npm version major && npm publish --access public",
12
- "publish:minor": "npm run build && npm version minor && npm publish --access public",
13
- "publish:patch": "npm run build && npm version patch && npm publish --access public"
7
+ "build": "npx @vnejs/monorepo package",
8
+ "publish:major:uis:react": "npm run publish:major",
9
+ "publish:minor:uis:react": "npm run publish:minor",
10
+ "publish:patch:uis:react": "npm run publish:patch",
11
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
12
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
13
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
14
14
  },
15
15
  "peerDependencies": {
16
- "@bem-react/classname": "1.5.12",
17
- "@vnejs/uis.utils": "~0.1.0",
18
- "react": "19.2.4",
19
- "react-dom": "19.2.4",
20
- "@vnejs/uis.react": "~0.1.0"
16
+ "@vnejs/uis.utils": "~0.1.0"
21
17
  },
22
18
  "devDependencies": {
23
- "@vnejs/uis.react": "~0.1.0",
24
- "typescript": "^5.7.3",
25
- "@types/react": "^19.0.10",
26
- "@types/react-dom": "^19.0.4"
19
+ "@vnejs/uis.react": "~0.1.0"
27
20
  },
28
21
  "files": [
29
22
  "dist",
30
- "package.json"
23
+ "src",
24
+ "tsconfig.json"
31
25
  ]
32
26
  }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./isRender.hook";
@@ -0,0 +1,44 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ import { useIsForceHook } from "@vnejs/uis.react";
4
+
5
+ const requestAnimationFrameWithCheckAndCallback = (rafObj, ref, cb) =>
6
+ requestAnimationFrame(() => {
7
+ if (!ref.current) rafObj.raf = requestAnimationFrameWithCheckAndCallback(rafObj, ref, cb);
8
+ else cb(true);
9
+ });
10
+
11
+ export const useIsRenderHook = (ref, isShow, isForce, transition) => {
12
+ const [isRender, setIsRender] = useState(false);
13
+ const [isRenderShow, setIsRenderShow] = useState(false);
14
+
15
+ const isRenderForce = useIsForceHook(isForce);
16
+
17
+ useEffect(() => {
18
+ if (!isShow || (isRender && isRenderShow)) return;
19
+
20
+ setIsRender(true);
21
+
22
+ if (isRenderForce) return void setIsRenderShow(true);
23
+
24
+ const rafObj: Record<string, any> = {};
25
+
26
+ rafObj.raf = requestAnimationFrameWithCheckAndCallback(rafObj, ref, setIsRenderShow);
27
+
28
+ return () => cancelAnimationFrame(rafObj.raf);
29
+ }, [isShow, isRenderForce, isRenderShow, isRender]);
30
+
31
+ useEffect(() => {
32
+ if (isShow || (!isRender && !isRenderShow)) return;
33
+
34
+ setIsRenderShow(false);
35
+
36
+ if (isRenderForce) return void setIsRender(false);
37
+
38
+ const tm = setTimeout(() => setIsRender(false), transition);
39
+
40
+ return () => clearTimeout(tm);
41
+ }, [isShow, isRenderForce, isRenderShow, isRender]);
42
+
43
+ return { isRender, isRenderShow, isRenderForce };
44
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "../../../tsconfig.react.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist",
5
+ "rootDir": "src"
6
+ },
7
+ "include": [
8
+ "src/**/*.ts",
9
+ "src/**/*.tsx",
10
+ "../../../globals.d.ts",
11
+ "../../../peer-modules.d.ts"
12
+ ],
13
+ "exclude": [
14
+ "dist",
15
+ "node_modules",
16
+ "src/**/*.stories.tsx"
17
+ ]
18
+ }