npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

use-next-tick

v1.1.3

Published

A React hook for running callbacks after the DOM or native views have updated.

Downloads

995

Readme

nextTick for React · Size npm version PRs Welcome GitHub license jsDocs.io typescript

A React hook for running callbacks after the DOM or native views have updated.

Why?

Sometimes you need to read layout, measure elements, or access refs right after a state change—but React updates asynchronously. useNextTick gives you a simple way to schedule code that runs after React commits your changes.

Install

npm install use-next-tick

Usage

"use client";
import { useState, useRef, useLayoutEffect } from "react";
import useNextTick, {useNextTickLayout} from "use-next-tick";

function MyComponent() {
  const [count, setCount] = useState(0);
  const ref = useRef<HTMLSpanElement>(null);
  const nextTick = useNextTick();
  /*
  const nextTick = useNextTickLayout(); // if you need `useLayoutEffect` instead off `useEffect`
  */

  const handleClick = () => {
    setCount((c) => c + 1);
    nextTick(() => {
      console.log(ref.current?.textContent); // "1" ✓
    });
  };

  return <span ref={ref}>{count}</span>;
}

What it does

  1. You update state with setState
  2. You call nextTick(callback)
  3. React re-renders and commits to DOM/native
  4. Your callback runs with updated refs and layout

When to use it

Use useNextTick when:

  • Measuring elements after a state change
  • Scrolling to newly rendered content
  • Reading layout values (width, height, position)
  • Focusing inputs after conditional rendering
  • One-off actions triggered by specific user events

Don't use it when:

  • You want something to happen on every render → use useEffect
  • You're just responding to prop/state changes → use useEffect with dependencies

Alternative without this hook

// Without useNextTick - requires separate useEffect
const [count, setCount] = useState(0);

const handleClick = () => {
  setCount((c) => c + 1);
};

useEffect(() => {
  // Runs after EVERY count change, not just from handleClick
  console.log(ref.current?.textContent);
}, [count]);

With useNextTick, you get imperative control—callbacks only run when you explicitly schedule them.

Online Demo

https://codesandbox.io/p/sandbox/react-dev-forked-jcljvj?file=%2Fsrc%2FApp.js%3A14%2C22

Platform support

Works on both React DOM (web) and React Native. Automatically uses the right scheduling mechanism for each platform.

Development

This project use bun.

bun install && bun run build

TypeScript

export default function useNextTick(useEffectHook?: typeof useEffect | typeof useLayoutEffect): (cb: NextTickCallback) => void;

Fully typed. Callbacks can be sync or async:

nextTick(() => {
  console.log("sync callback");
});

nextTick(async () => {
  await someAsyncWork();
});

Reporting Issues

Found an issue? Please feel free to create issue

Support

If you find this project helpful, consider buying me a coffee.

Projects You May Also Be Interested In

  • xior - Tiny fetch library with plugins support and axios-like API
  • tsdk - Type-safe API development CLI tool for TypeScript projects
  • broad-infinite-list - ⚡ High performance and Bidirectional infinite scrolling list component for React and Vue3