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 🙏

© 2025 – Pkg Stats / Ryan Hefner

noob-store

v1.0.3

Published

A noob state management library

Downloads

12

Readme

NoobStore

A lightweight and simple React state management library with support for both local state and server state.

Installation

npm install noob-store

Features

  • 🪶 Lightweight and simple API
  • 🔄 Local state management
  • 🌐 Server state management with loading, error states
  • 📦 TypeScript support
  • 🎯 Zero dependencies (except React)

Usage

Local State Management

First, create your store:

// stores/counterStore.ts
import { createStore } from "noob-store";

// Create and export a store
export const counterStore = createStore(0);

Then, use it in any components:

// components/Counter.tsx
import { useStore } from "noob-store";
import { counterStore } from "../stores/counterStore";

function Counter() {
  const [count, setCount] = useStore(counterStore);

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={() => setCount(count + 1)}>Increment</button>
      {/* Using function update syntax */}
      <button onClick={() => setCount(prev => prev + 1)}>Increment (using function)</button>
    </div>
  );
}

With Selector

Create a store with a selector:

// stores/userStore.ts
import { createStore } from "noob-store";

export const userStore = createStore(
  { name: "John", age: 30, email: "[email protected]" },
  (state) => ({ name: state.name, age: state.age }) // Only select name and age
);

Use it in any components:

// components/UserInfo.tsx
import { useStore } from "noob-store";
import { userStore } from "../stores/userStore";

function UserInfo() {
  const [user, setUser] = useStore(userStore);
  
  // user will only contain name and age
  return (
    <div>
      <p>Name: {user.name}</p>
      <p>Age: {user.age}</p>
      <button onClick={() => setUser(prev => ({ ...prev, age: prev.age + 1 }))}>
        Happy Birthday!
      </button>
    </div>
  );
}

Server State Management

Create a server store:

// stores/userServerStore.ts
import { createServerStore } from "noob-store";

export const userStore = createServerStore(null, async () => {
  const response = await fetch("https://api.example.com/user");
  return response.json();
});

Use it in any components:

// components/UserProfile.tsx
import { useServerStore } from "noob-store";
import { userStore } from "../stores/userServerStore";

function UserProfile() {
  const [user, refetch, status] = useServerStore(userStore);

  if (status.isLoading) return <div>Loading...</div>;
  if (status.isError) return <div>Error: {status.error.message}</div>;
  if (!user) return <div>No user data</div>;

  return (
    <div>
      <h1>{user.name}</h1>
      <button onClick={refetch}>Refresh</button>
    </div>
  );
}

Server Store with Selector

Create a server store with a selector:

// stores/postsStore.ts
import { createServerStore } from "noob-store";

export const postsStore = createServerStore(
  [],
  async () => {
    const response = await fetch("https://api.example.com/posts");
    return response.json();
  },
  (posts) => posts.filter(post => post.published) // Only select published posts
);

Use it in any components:

// components/PublishedPosts.tsx
import { useServerStore } from "noob-store";
import { postsStore } from "../stores/postsStore";

function PublishedPosts() {
  const [posts, refetch, status] = useServerStore(postsStore);
  
  if (status.isLoading) return <div>Loading...</div>;
  if (status.isError) return <div>Error: {status.error.message}</div>;
  
  return (
    <div>
      <h1>Published Posts</h1>
      {posts.map(post => (
        <div key={post.id}>{post.title}</div>
      ))}
      <button onClick={refetch}>Refresh</button>
    </div>
  );
}

API Reference

createStore<T>(initialState: T, getter?: (state: T) => any)

Creates a local state store.

useStore<T>(store: Store<T>): [T, (value: T | ((prevState: T) => T)) => void]

Hook to use a local store in a component. The setState function can accept either:

  • A new state value
  • A function that receives the previous state and returns a new state, similar to React's setState

createServerStore<T>(initialState: T, refetchFunction: () => Promise<T>, getter?: (state: T) => any)

Creates a server state store with fetching capabilities.

useServerStore<T>(serverStore: ServerStore<T>): [T, () => void, { isLoading: boolean, isError: boolean, error: Error | null }]

Hook to use a server store in a component. Returns:

  • Selected state
  • Refetch function
  • Status object containing:
    • isLoading: boolean indicating if data is being fetched
    • isError: boolean indicating if an error occurred
    • error: Error object (if any)