use-next-tick 1.0.0-alpha.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 su
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # [nextTick for React](https://suhaotian.github.io/use-next-tick/) · [![Size](https://deno.bundlejs.com/badge?q=use-next-tick/react&treeshake=[{default}]&config={%22esbuild%22:{%22external%22:[%22react%22,%22react-dom%22,%22react/jsx-runtime%22]}})](https://bundlejs.com/?q=use-next-tick/react&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) [![npm version](https://img.shields.io/npm/v/use-next-tick.svg?style=flat)](https://www.npmjs.com/package/use-next-tick) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/suhaotian/use-next-tick/pulls) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/suhaotian/use-next-tick/blob/main/LICENSE) [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/use-next-tick) ![typescript](https://badgen.net/badge/icon/typescript?icon=typescript&label&color=blue)
2
+
3
+ **use-next-tick** is a React hook that queues callbacks to run in useLayoutEffect after the next render — similar to Vue's nextTick.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install use-next-tick
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```tsx
14
+ "use client";
15
+ import { useState, useRef } from "react";
16
+ import useNextTick from "use-next-tick";
17
+
18
+ function MyComponent() {
19
+ const [count, setCount] = useState(0);
20
+ const ref = useRef<HTMLSpanElement>(null);
21
+ const nextTick = useNextTick();
22
+
23
+ const handleClick = () => {
24
+ setCount((c) => c + 1);
25
+ nextTick(() => {
26
+ // DOM is already updated here
27
+ console.log(ref.current?.textContent); // "1"
28
+ });
29
+ };
30
+
31
+ return <span ref={ref}>{count}</span>;
32
+ }
33
+ ```
34
+
35
+ ### API
36
+
37
+ ```ts
38
+ function useNextTick(): (cb: () => void | Promise<void>) => void;
39
+ ```
40
+
41
+ ## Development
42
+
43
+ This project use bun.
44
+
45
+ ```sh
46
+ bun install && bun run build
47
+ ```
48
+
49
+ ## Reporting Issues
50
+
51
+ Found an issue? Please feel free to [create issue](https://github.com/suhaotian/use-next-tick/issues/new)
52
+
53
+ ## Support
54
+
55
+ If you find this project helpful, consider [buying me a coffee](https://github.com/suhaotian/use-next-tick/stargazers).
56
+
57
+ ## Projects You May Also Be Interested In
58
+
59
+ - [xior](https://github.com/suhaotian/xior) - Tiny fetch library with plugins support and axios-like API
60
+ - [tsdk](https://github.com/tsdk-monorepo/tsdk) - Type-safe API development CLI tool for TypeScript projects
61
+ - [broad-infinite-list](https://github.com/suhaotian/broad-infinite-list) - ⚡ High performance and Bidirectional infinite scrolling list component for React and Vue3
@@ -0,0 +1,2 @@
1
+ export type NextTickCallback = () => void | Promise<void>;
2
+ export default function useNextTick(): (cb: NextTickCallback) => void;
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import{useState as A,useLayoutEffect as B,useRef as D,useCallback as F}from"react";function G(){let[x,z]=A(0),j=D([]);return B(()=>{if(x===0)return;let v=j.current;j.current=[];for(let w of v)w()},[x]),F((v)=>{j.current.push(v),z((w)=>w+1)},[])}export{G as default};
2
+
3
+ //# debugId=91B7EB10381DE00564756E2164756E21
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": [
5
+ "import { useState, useLayoutEffect, useRef, useCallback } from \"react\";\n\nexport type NextTickCallback = () => void | Promise<void>;\n\nexport default function useNextTick(): (cb: NextTickCallback) => void {\n const [tick, setTick] = useState(0);\n const callbacksRef = useRef<NextTickCallback[]>([]);\n\n useLayoutEffect(() => {\n // Skip the initial mount — nothing is queued yet.\n if (tick === 0) return;\n\n const pending = callbacksRef.current;\n callbacksRef.current = [];\n for (const cb of pending) {\n cb();\n }\n }, [tick]);\n\n const nextTick = useCallback((cb: NextTickCallback) => {\n callbacksRef.current.push(cb);\n setTick((c) => c + 1);\n }, []);\n\n return nextTick;\n}\n"
6
+ ],
7
+ "mappings": "AAAA,mBAAS,qBAAU,YAAiB,iBAAQ,cAI5C,SAAwB,CAAW,EAAmC,CACpE,IAAO,EAAM,GAAW,EAAS,CAAC,EAC5B,EAAe,EAA2B,CAAC,CAAC,EAkBlD,OAhBA,EAAgB,IAAM,CAEpB,GAAI,IAAS,EAAG,OAEhB,IAAM,EAAU,EAAa,QAC7B,EAAa,QAAU,CAAC,EACxB,QAAW,KAAM,EACf,EAAG,GAEJ,CAAC,CAAI,CAAC,EAEQ,EAAY,CAAC,IAAyB,CACrD,EAAa,QAAQ,KAAK,CAAE,EAC5B,EAAQ,CAAC,IAAM,EAAI,CAAC,GACnB,CAAC,CAAC",
8
+ "debugId": "91B7EB10381DE00564756E2164756E21",
9
+ "names": []
10
+ }
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "use-next-tick",
3
+ "version": "1.0.0-alpha.0",
4
+ "description": "React hook that queues callbacks to run in useLayoutEffect after the next render — similar to Vue's nextTick",
5
+ "repository": "suhaotian/use-next-tick",
6
+ "bugs": "https://github.com/suhaotian/use-next-tick/issues",
7
+ "homepage": "https://suhaotian.github.io/use-next-tick",
8
+ "type": "module",
9
+ "main": "./dist/index.js",
10
+ "module": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/index.js",
15
+ "types": "./dist/index.d.ts"
16
+ }
17
+ },
18
+ "workspaces": [
19
+ "demos/**",
20
+ "./**"
21
+ ],
22
+ "devDependencies": {
23
+ "@types/bun": "latest",
24
+ "@types/react": "^19.2.10",
25
+ "@types/react-dom": "^19.2.3",
26
+ "react": "19.1.0",
27
+ "react-dom": "19.1.0",
28
+ "typescript": "^5.9.3"
29
+ },
30
+ "peerDependencies": {
31
+ "react": ">=19"
32
+ },
33
+ "peerDependenciesMeta": {
34
+ "react-dom": {
35
+ "optional": true
36
+ }
37
+ },
38
+ "scripts": {
39
+ "build": "rm -rf dist && bun build.ts && tsc --emitDeclarationOnly"
40
+ },
41
+ "files": [
42
+ "dist",
43
+ "package.json",
44
+ "LICENSE",
45
+ "README.md"
46
+ ],
47
+ "keywords": [
48
+ "react",
49
+ "nextTick",
50
+ "nextTick hook",
51
+ "useLayoutEffect"
52
+ ],
53
+ "author": {
54
+ "name": "@suhaotian",
55
+ "url": "https://github.com/suhaotian"
56
+ },
57
+ "license": "MIT"
58
+ }