use-next-tick 1.0.3 → 1.1.1
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/README.md +4 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/dist/react-native.d.ts +2 -0
- package/dist/react-native.js +4 -0
- package/dist/react-native.js.map +10 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -75,6 +75,10 @@ useEffect(() => {
|
|
|
75
75
|
|
|
76
76
|
With `useNextTick`, you get **imperative control**—callbacks only run when you explicitly schedule them.
|
|
77
77
|
|
|
78
|
+
## Online Demo
|
|
79
|
+
|
|
80
|
+
https://codesandbox.io/p/sandbox/react-dev-forked-jcljvj?file=%2Fsrc%2FApp.js%3A14%2C22
|
|
81
|
+
|
|
78
82
|
## Platform support
|
|
79
83
|
|
|
80
84
|
Works on both **React DOM** (web) and **React Native**. Automatically uses the right scheduling mechanism for each platform.
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{useEffect as
|
|
1
|
+
import{useEffect as i,useRef as r,useCallback as o}from"react";function u(){let e=r([]),c=r(!1);return i(()=>{if(!c.current)return;c.current=!1;let t=e.current;e.current=[];for(let n of t)n()}),o((t)=>{e.current.push(t),c.current=!0},[])}export{u as default};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=1994852A3252699764756E2164756E21
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { useEffect, useRef, useCallback } from \"react\";\n\nexport type NextTickCallback = () => void | Promise<void>;\n\nexport default function useNextTick(): (cb: NextTickCallback) => void {\n const callbacksRef = useRef<NextTickCallback[]>([]);\n const pendingRef = useRef(false);\n\n useEffect(() => {\n if (!pendingRef.current) return;\n\n pendingRef.current = false;\n const pending = callbacksRef.current;\n callbacksRef.current = [];\n
|
|
5
|
+
"import { useEffect, useRef, useCallback } from \"react\";\n\nexport type NextTickCallback = () => void | Promise<void>;\n\nexport default function useNextTick(): (cb: NextTickCallback) => void {\n const callbacksRef = useRef<NextTickCallback[]>([]);\n const pendingRef = useRef(false);\n\n useEffect(() => {\n if (!pendingRef.current) return;\n\n pendingRef.current = false;\n const pending = callbacksRef.current;\n callbacksRef.current = [];\n for (const cb of pending) {\n cb();\n }\n });\n\n const nextTick = useCallback((cb: NextTickCallback) => {\n callbacksRef.current.push(cb);\n pendingRef.current = true;\n }, []);\n\n return nextTick;\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "AAAA,oBAAS,YAAW,iBAAQ,cAI5B,SAAwB,CAAW,EAAmC,CACpE,IAAM,EAAe,EAA2B,CAAC,CAAC,EAC5C,EAAa,EAAO,EAAK,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "AAAA,oBAAS,YAAW,iBAAQ,cAI5B,SAAwB,CAAW,EAAmC,CACpE,IAAM,EAAe,EAA2B,CAAC,CAAC,EAC5C,EAAa,EAAO,EAAK,EAkB/B,OAhBA,EAAU,IAAM,CACd,GAAI,CAAC,EAAW,QAAS,OAEzB,EAAW,QAAU,GACrB,IAAM,EAAU,EAAa,QAC7B,EAAa,QAAU,CAAC,EACxB,QAAW,KAAM,EACf,EAAG,EAEN,EAEgB,EAAY,CAAC,IAAyB,CACrD,EAAa,QAAQ,KAAK,CAAE,EAC5B,EAAW,QAAU,IACpB,CAAC,CAAC",
|
|
8
|
+
"debugId": "1994852A3252699764756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{useEffect as i,useRef as r,useCallback as o}from"react";function u(){let e=r([]),t=r(!1);return i(()=>{if(!t.current)return;t.current=!1;let c=e.current;e.current=[],setTimeout(()=>{for(let n of c)n()},0)}),o((c)=>{e.current.push(c),t.current=!0},[])}export{u as default};
|
|
2
|
+
|
|
3
|
+
//# debugId=3B7FF0A1E8F2680564756E2164756E21
|
|
4
|
+
//# sourceMappingURL=react-native.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/react-native.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { useEffect, useRef, useCallback } from \"react\";\n\nexport type NextTickCallback = () => void | Promise<void>;\n\nexport default function useNextTick(): (cb: NextTickCallback) => void {\n const callbacksRef = useRef<NextTickCallback[]>([]);\n const pendingRef = useRef(false);\n\n useEffect(() => {\n if (!pendingRef.current) return;\n\n pendingRef.current = false;\n const pending = callbacksRef.current;\n callbacksRef.current = [];\n setTimeout(() => {\n for (const cb of pending) {\n cb();\n }\n }, 0);\n });\n\n const nextTick = useCallback((cb: NextTickCallback) => {\n callbacksRef.current.push(cb);\n pendingRef.current = true;\n }, []);\n\n return nextTick;\n}\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "AAAA,oBAAS,YAAW,iBAAQ,cAI5B,SAAwB,CAAW,EAAmC,CACpE,IAAM,EAAe,EAA2B,CAAC,CAAC,EAC5C,EAAa,EAAO,EAAK,EAoB/B,OAlBA,EAAU,IAAM,CACd,GAAI,CAAC,EAAW,QAAS,OAEzB,EAAW,QAAU,GACrB,IAAM,EAAU,EAAa,QAC7B,EAAa,QAAU,CAAC,EACxB,WAAW,IAAM,CACf,QAAW,KAAM,EACf,EAAG,GAEJ,CAAC,EACL,EAEgB,EAAY,CAAC,IAAyB,CACrD,EAAa,QAAQ,KAAK,CAAE,EAC5B,EAAW,QAAU,IACpB,CAAC,CAAC",
|
|
8
|
+
"debugId": "3B7FF0A1E8F2680564756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-next-tick",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A React hook for running callbacks after the DOM or native views have updated.",
|
|
5
5
|
"repository": "suhaotian/use-next-tick",
|
|
6
6
|
"bugs": "https://github.com/suhaotian/use-next-tick/issues",
|
|
7
7
|
"homepage": "https://suhaotian.github.io/use-next-tick",
|
|
8
8
|
"main": "./dist/index.js",
|
|
9
9
|
"module": "./dist/index.js",
|
|
10
|
+
"react-native": "./dist/react-native.js",
|
|
10
11
|
"types": "./dist/index.d.ts",
|
|
11
12
|
"exports": {
|
|
12
13
|
".": {
|
|
13
14
|
"import": "./dist/index.js",
|
|
15
|
+
"react-native": "./dist/react-native.js",
|
|
14
16
|
"types": "./dist/index.d.ts"
|
|
15
17
|
}
|
|
16
18
|
},
|