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

vanillastates

v1.0.2

Published

Implementation of React States in Vanilla JS

Readme

VanillaStates

A small state management implementation inspired by React's useState and useEffect. Built from scratch — without React, without VDOM, just raw logic using global objects and function references — which makes it perfect to use in Vanilla JavaScript.


Installation

npm i vanillastates

Then:

import { useState, useEffect } from "vanillastates";

useState(initialValue)

Usage:

const [count, setCount] = useState(0);

console.log(count()); // → 0

setCount((prev) => prev + 1);
console.log(count()); // → 1

Returns:

  • getter() → Returns the current state value. If passed a truthy param (e.g. "get-id"), returns internal ID (used for tracking).
  • setState(fn) → Function-based setter. Pass a function that receives the current value and returns the next one.

useEffect(fn, dependencies)

Usage:

useEffect(() => {
  console.log("count changed:", count());
}, [count]);

Behavior:

  • Accepts a function and an array of getter functions from useState.
  • Internally maps each dependency’s ID to the given function.
  • Runs the effect immediately after setup.
  • Re-runs only when the respective state changes.

🔧 Internal Flow

  • global.ids: { [id]: stateValue }
  • global.changeHooks: { [id]: callbackFn }
  1. useState assigns a unique sequential ID to every state.
  2. useEffect maps that ID to a callback, and calls it once immediately.
  3. setState updates the value and calls the corresponding effect (via handleChanges).

🔨 handleChanges(id)

Internal function. You don’t need to call this manually unless you're triggering effect execution outside the usual flow.


Example

const [count, setCount] = useState(0);
const [name, setName] = useState("Bavi");

useEffect(() => {
  console.log("Count is:", count());
}, [count]);

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

setCount((c) => c + 1);      // Logs: "Count is: 1"
setName((n) => "Baltej");    // Logs: "Hello Baltej"

Notes

  • This is not a replacement for React. It’s a lightweight concept showing how hooks can be mimicked.
  • getter("get-id") returns the internal ID used by useEffect to track dependencies.
  • Clear error messages are thrown if you pass invalid parameters to useState or useEffect.