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

@krsamir/react-utils

v1.0.2

Published

A React Helper Library

Readme

use-why-effect-ran

A lightweight React debugging hook that tells you which dependency caused a component's useEffect to re-run.

Useful when tracking down unnecessary renders, unstable references, or unexpected effect executions.

Features

  • 🔍 Shows exactly which dependency changed
  • 📊 Logs previous and current values
  • ⚛️ Works with any React hook dependency array
  • 🪶 Zero runtime dependencies
  • 📦 TypeScript support included
  • 🌳 Tree-shakeable

Installation

npm i @krsamir/react-utils
yarn add @krsamir/react-utils

Usage

Basic Example

import { useEffect, useState } from "react";
import { useWhyEffectRan } from "@krsamir/react-utils";

export default function App() {
  const [count, setCount] = useState(0);
  const [name, setName] = useState("Samir");

  useWhyEffectRan([count, name], ["count", "name"]);

  useEffect(() => {
    console.log("Effect executed");
  }, [count, name]);

  return (
    <>
      <button onClick={() => setCount((c) => c + 1)}>Count: {count}</button>

      <button onClick={() => setName("John")}>Change Name</button>
    </>
  );
}

Console Output

When count changes:

useEffect re-ran because:

┌─────────┬──────┬────┐
│ (index) │ from │ to │
├─────────┼──────┼────┤
│ count   │  1   │ 2  │
└─────────┴──────┴────┘

When multiple dependencies change:

useEffect re-ran because:

┌─────────┬────────┬────────┐
│ (index) │ from   │ to     │
├─────────┼────────┼────────┤
│ count   │ 1      │ 2      │
│ name    │ Samir  │ John   │
└─────────┴────────┴────────┘

API

useWhyEffectRan

useWhyEffectRan(
  dependencies: DependencyList,
  dependencyNames?: readonly string[]
): void;

Parameters

| Parameter | Type | Description | | ----------------- | ------------------- | ------------------------------------------------- | | dependencies | DependencyList | The dependency array you want to inspect | | dependencyNames | readonly string[] | Optional human-readable names for each dependency |


Example with Objects

const filters = {
  status: "ACTIVE",
};

useWhyEffectRan([filters], ["filters"]);

useEffect(() => {
  fetchData(filters);
}, [filters]);

Console output:

useEffect re-ran because:

filters:
  from: { status: "ACTIVE" }
  to:   { status: "ACTIVE" }

This often indicates a new object reference is being created on each render.


Example with Functions

const handleSubmit = () => {
  // submit logic
};

useWhyEffectRan([handleSubmit], ["handleSubmit"]);

If the function is recreated every render, the hook will show it as changed.

Consider using:

const handleSubmit = useCallback(() => {
  // submit logic
}, []);

Why Use This?

A common situation:

useEffect(() => {
  fetchData();
}, [filters, sortBy, page]);

The effect keeps running, but it's unclear which dependency changed.

With:

useWhyEffectRan([filters, sortBy, page], ["filters", "sortBy", "page"]);

you can immediately see what triggered the effect.


TypeScript Support

This package ships with built-in TypeScript definitions.

import { useWhyEffectRan } from "@krsamir/react-utils";

No additional type packages are required.


Requirements

| Package | Version | | ------- | ------- | | React | >= 18 |


Notes

  • Intended for debugging and development workflows.
  • Uses Object.is() for dependency comparison, matching React's dependency checking behavior.
  • Logs changes using console.group() and console.table().

License

MIT


Author

Samir Kumar

GitHub: https://github.com/krsamir