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

@agusmgarcia/react-essentials-store

v0.21.0

Published

Set of opinionated state manager for NextJS applications, libraries and Azure functions

Readme

React Essentials Store

An opinionated state manager. It provides tools to create global and server states.

Global slice

This is the state that is going to be consumed globally across the app. It is handled by the GlobalSlice class. It can be read and written.

// ./src/store/FormSearchSlice.ts

import { GlobalSlice } from "@agusmgarcia/react-essentials-store";
import { type Func } from "@agusmgarcia/react-essentials-utils";

export type State = {
  asc: boolean;
  clear: Func;
  name: string;
};

export default class FormSearchSlice extends GlobalSlice<State> {
  constructor() {
    super({ asc: false, name: "" });
  }

  clear(): void {
    this.state = { asc: false, name: "" };
  }

  setAsc(asc: boolean): void {
    this.state = { ...this.state, asc };
  }

  setName(name: string): void {
    this.state = { ...this.state, name };
  }
}

Server slice

The state that is populated from an API or an external resource. It is handled by the ServerSlice class. Due the way it gets originated, it can be read only.

// ./src/store/FormResultSlice.ts

import { ServerSlice } from "@agusmgarcia/react-essentials-store";
import { type Func } from "@agusmgarcia/react-essentials-utils";

import type FormSearchSlice from "./FormSearchSlice";
import { type FormSearch } from "./FormSearchSlice";

export type Request = Pick<FormSearch, "asc", "name">;

export type Response = {
  age: number;
  name: string;
  surname: string;
}[];

export default class FormResultSlice extends ServerSlice<
  Response | undefined,
  Request,
  { formSearch: FormSearchSlice }
> {
  constructor() {
    super(undefined);
  }

  protected override onRequestBuild(): Request {
    return {
      asc: this.slices.formSearch.state.asc,
      name: this.slices.formSearch.state.name,
    };
  }

  protected override onFetch(request: Request, signal: AbortSignal): Response {
    return fetch(`/api/search?asc=${request.asc}&name=${request.name}`, {
      signal,
    }).then((result) => result.json());
  }
}

Store

The slices are gathered into a store object. It is handled by createStore function. The slices are passed as arguments. Then, they can be accessed thru the useSelector hook. You can create custom hooks that access the different pieces of each slice as described in the example below:

// ./src/store/index.ts

import { createReactStore } from "@agusmgarcia/react-essentials-store";

import FormSearchSlice from "./FormSearchSlice";
import FormResultSlice from "./FormResultSlice";

const { useSelector, ...reactStore } = createReactStore({
  slices: {
    formSearch: FormSearchSlice,
    formResult: FormResultSlice,
  },
});

export const StoreProvider = reactStore.StoreProvider;

export function useFormSearch() {
  return {
    clearFormSearch: useSelector((state) => state.formSearch.clear),
    formSearchAsc: useSelector((state) => state.formSearch.state.asc),
    formSearchName: useSelector((state) => state.formSearch.state.name),
    setFormSearchAsc: useSelector((state) => state.formSearch.setAsc),
    setFormSearchName: useSelector((state) => state.formSearch.setName),
  };
}

export function useFormResult() {
  return {
    formResult: useSelector((state) => state.formResult.response),
    formResultError: useSelector((state) => state.formResult.error),
    formResultLoading: useSelector((state) => state.formResult.loading),
    formResultReload: useSelector((state) => state.formResult.reload),
  };
}

Make sure to export the StoreProvider component as it is going to be used in the entry point of the app.

Wrap the main component with the created StoreProvider component

// ./pages/_app.tsx

import "./_app.css";

import { type AppProps } from "next/app";
import Head from "next/head";

import { StoreProvider } from "#src/store";

export default function App({ Component, pageProps }: AppProps<any>) {
  return (
    <>
      <Head>
        <meta content="width=device-width, initial-scale=1" name="viewport" />
      </Head>

      <StoreProvider>
        <Component {...pageProps} />
      </StoreProvider>
    </>
  );
}