use-next-tick 1.0.0 → 1.0.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 +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# [nextTick for React](https://suhaotian.github.io/use-next-tick/) · [](https://bundlejs.com/?q=use-next-tick&treeshake=%5B%7Bdefault%7D%5D&config=%7B%22esbuild%22:%7B%22external%22:%5B%22react%22,%22react-dom%22,%22react/jsx-runtime%22%5D%7D%7D) [](https://www.npmjs.com/package/use-next-tick) [](https://github.com/suhaotian/use-next-tick/pulls) [](https://github.com/suhaotian/use-next-tick/blob/main/LICENSE) [](https://www.jsdocs.io/package/use-next-tick) 
|
|
2
2
|
|
|
3
|
-
**use-next-tick** is a React hook that runs a callback in `
|
|
3
|
+
**use-next-tick** is a React hook that runs a callback in `useEffect` after the next render, similar to Vue’s `nextTick`.
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
## Installation
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{useEffect as x,useRef as q,useCallback as y}from"react";function z(){let h=q([]),j=q(!1);return x(()=>{if(!j.current)return;j.current=!1;let m=h.current;h.current=[];for(let v of m)v()}),y((m)=>{h.current.push(m),j.current=!0},[])}export{z as default};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=5D791060BB3A46CA64756E2164756E21
|
|
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 {
|
|
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\n // DOM is now updated, run callbacks\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,
|
|
8
|
-
"debugId": "
|
|
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,EAGxB,QAAW,KAAM,EACf,EAAG,EAEN,EAEgB,EAAY,CAAC,IAAyB,CACrD,EAAa,QAAQ,KAAK,CAAE,EAC5B,EAAW,QAAU,IACpB,CAAC,CAAC",
|
|
8
|
+
"debugId": "5D791060BB3A46CA64756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-next-tick",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "React hook that queues callbacks to run in
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "React hook that queues callbacks to run code in useEffect after the next render — similar to Vue's nextTick",
|
|
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",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"react",
|
|
33
33
|
"nextTick",
|
|
34
34
|
"nextTick hook",
|
|
35
|
-
"
|
|
35
|
+
"useEffect"
|
|
36
36
|
],
|
|
37
37
|
"author": {
|
|
38
38
|
"name": "@suhaotian",
|