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-god-state

v1.0.8

Published

Simplify your React/Preact state management. One hook to replace multiple useState calls with validation, persistence, dirty tracking, and granular field control.

Downloads

25

Readme

use-god-state

Simplifica la gestión de estado en React/Preact con un solo hook.
Incluye validación, persistencia, seguimiento de cambios (dirty), y control granular de campos.

Instalación

npm install use-god-state

Asegúrate de tener preact instalado como dependencia (o como peerDependency si es una librería):

npm install preact

Uso básico

import { useGodState } from "use-god-state";

const initialState = { nombre: "", edad: 0 };

function MiComponente() {
  const [state, setState] = useGodState(initialState);

  return (
    <div>
      <input
        value={state.nombre.val}
        onInput={e => state.nombre.set(e.currentTarget.value)}
      />
      <input
        type="number"
        value={state.edad.val}
        onInput={e => state.edad.set(Number(e.currentTarget.value))}
      />
      <button onClick={state.reset}>Restablecer</button>
      <div>¿Hay cambios? {state.isDirty ? "Sí" : "No"}</div>
    </div>
  );
}

Opciones avanzadas

Puedes pasar un objeto de opciones para agregar validaciones, middlewares, persistencia y más:

const [state, setState] = useGodState(
  { nombre: "", edad: 0 },
  {
    validators: {
      nombre: v => v.length > 0 || "El nombre es obligatorio",
      edad: v => v >= 0 || "La edad debe ser positiva"
    },
    middleware: [
      (key, value) => (key === "nombre" ? value.trim() : value)
    ],
    persist: {
      key: "mi-estado",
      // storage: sessionStorage, // Opcional
      // serialize: (state) => customSerialize(state),
      // deserialize: (str) => customDeserialize(str)
    },
    debounceMs: 300,
    onStateChange: (nuevo, anterior, key) => {
      console.log("Cambio de estado:", key, nuevo);
    }
  }
);

API del estado

Cada campo tiene:

  • .val — valor actual
  • .set(valor) — actualiza el valor
  • .reset() — restablece al valor inicial
  • .isDirty — indica si fue modificado

El objeto principal tiene:

  • .reset() — restablece todo el estado
  • .resetDirty() — limpia el seguimiento de cambios
  • .isDirty — indica si algún campo cambió
  • .getSnapshot() — obtiene una copia del estado actual
  • .restoreSnapshot(snapshot) — restaura un snapshot

Ejemplo de validación y persistencia

const [state] = useGodState(
  { email: "" },
  {
    validators: {
      email: v => /\S+@\S+\.\S+/.test(v) || "Email inválido"
    },
    persist: { key: "form-email" }
  }
);

Notas

  • Compatible con Preact (v10+) y proyectos TypeScript.
  • Si usas React, puedes adaptar el hook fácilmente cambiando los imports.

¿Dudas o sugerencias? ¡Abre un issue o contribuye!