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

zeiger

v0.3.0

Published

Create memoized collection pointer with Zustand state mangement library

Readme

Zeiger

Simplified memoized collection item selectors for Zustand.

Zeiger eliminates unnecessary re-renders when working with collections in Zustand stores by providing fine-grained, memoized selectors that only trigger updates when the specific properties you care about actually change.

Installation

npm install zeiger zustand
pnpm add zeiger zustand
yarn add zeiger zustand

The Problem

When working with collections in Zustand, selecting items often causes unnecessary re-renders:

// This re-renders whenever ANY property of ANY todo changes
const todos = useStore((state) => state.todos);

// Even with shallow comparison, changes to unrelated properties cause re-renders
const todos = useStore((state) => state.todos, shallow);

The Solution

Zeiger provides pointer factories that create memoized selectors, only re-rendering when the specific properties you depend on change:

// Only re-renders when 'id' or 'title' of any todo changes
const todos = useTodosPointer(['id', 'title']);

// Only re-renders when 'completed' of this specific todo changes
const todo = useTodoItemPointer('todo-1', ['completed']);

API Reference

createCollectionPointer

Creates a hook for selecting multiple items from a collection with fine-grained reactivity.

function createCollectionPointer<Store, CollectionKey>(
  store: Store,
  collectionKey: CollectionKey
): (
  deps: PropertyKey[],
  filterFn?: (item: Item, state: State) => boolean
) => Pick<Item, Dep>[];

Parameters

| Parameter | Type | Description | | --------------- | ---------------------------- | ------------------------------------------- | | store | UseBoundStore<StoreApi<S>> | Your Zustand store | | collectionKey | keyof State | The key of the array property in your store |

Returns

A hook function that accepts:

| Parameter | Type | Description | | ---------- | -------------------------- | ------------------------------------------ | | deps | (keyof Item)[] | Array of property keys to select and track | | filterFn | (item, state) => boolean | Optional filter function |

Example

import { create } from 'zustand';
import { createCollectionPointer } from 'zeiger';

interface Todo {
  id: string;
  title: string;
  completed: boolean;
  description: string;
}

interface Store {
  todos: Todo[];
  filter: 'all' | 'active' | 'completed';
}

const useStore = create<Store>(() => ({
  todos: [],
  filter: 'all',
}));

// Create the pointer
const useTodosPointer = createCollectionPointer(useStore, 'todos');

// In your component
function TodoList() {
  // Only re-renders when 'id' or 'title' changes
  const todos = useTodosPointer(['id', 'title']);

  return (
    <ul>
      {todos.map((todo) => (
        <li key={todo.id}>{todo.title}</li>
      ))}
    </ul>
  );
}

// With filtering
function ActiveTodoList() {
  const activeTodos = useTodosPointer(
    ['id', 'title'],
    (todo) => !todo.completed
  );

  return (
    <ul>
      {activeTodos.map((todo) => (
        <li key={todo.id}>{todo.title}</li>
      ))}
    </ul>
  );
}

createCollectionItemPointer

Creates a hook for selecting a single item from a collection by its unique identifier.

function createCollectionItemPointer<Store, CollectionKey, UniqueKey>(
  store: Store,
  collectionKey: CollectionKey,
  itemUniqueKey: UniqueKey
): (
  itemUniqueValue: string,
  deps: PropertyKey[]
) => Pick<Item, Dep> | undefined;

Parameters

| Parameter | Type | Description | | --------------- | ---------------------------- | -------------------------------------------- | | store | UseBoundStore<StoreApi<S>> | Your Zustand store | | collectionKey | keyof State | The key of the array property in your store | | itemUniqueKey | keyof Item | The property used to uniquely identify items |

Returns

A hook function that accepts:

| Parameter | Type | Description | | ----------------- | ---------------- | ------------------------------------------ | | itemUniqueValue | string | The unique identifier value of the item | | deps | (keyof Item)[] | Array of property keys to select and track |

Returns undefined if the item is not found.

Example

import { create } from 'zustand';
import { createCollectionItemPointer } from 'zeiger';

interface Todo {
  id: string;
  title: string;
  completed: boolean;
  description: string;
}

interface Store {
  todos: Todo[];
}

const useStore = create<Store>(() => ({
  todos: [],
}));

// Create the pointer with 'id' as the unique key
const useTodoItemPointer = createCollectionItemPointer(useStore, 'todos', 'id');

// In your component
function TodoItem({ todoId }: { todoId: string }) {
  // Only re-renders when 'title' or 'completed' of THIS todo changes
  const todo = useTodoItemPointer(todoId, ['title', 'completed']);

  if (!todo) return null;

  return (
    <div>
      <span
        style={{ textDecoration: todo.completed ? 'line-through' : 'none' }}
      >
        {todo.title}
      </span>
    </div>
  );
}

Benefits

  • Eliminates unnecessary re-renders - Components only update when their specific dependencies change
  • Fine-grained reactivity - Select exactly which properties to track per component
  • Type-safe - Full TypeScript support with autocomplete for collection keys and item properties. The returned object type only includes properties listed in deps, so TypeScript will error if you try to access unlisted properties.
  • Minimal API - Just two functions to learn
  • Built-in filtering - Filter collections without additional selectors
  • Zero configuration - Works out of the box with any Zustand store
  • Lightweight - Tiny bundle size with no external dependencies beyond Zustand

ESLint Plugin

For the best development experience, use zeiger-eslint-plugin to automatically catch common mistakes:

  • Empty dependency arrays
  • Unused properties in dependency arrays
npm install --save-dev zeiger-eslint-plugin

See the plugin documentation for setup instructions.

Type Safety

Zeiger is fully typed. When you specify properties in the deps array, the returned object is typed to only include those properties. This means TypeScript will catch errors at compile time if you try to access a property that wasn't listed in deps:

const useTodosPointer = createCollectionPointer(useStore, 'todos');

function TodoList() {
  const todos = useTodosPointer(['id', 'title']);

  return (
    <ul>
      {todos.map((todo) => (
        // ✅ Works - 'id' and 'title' are in deps
        <li key={todo.id}>{todo.title}</li>

        // ❌ TypeScript Error - 'completed' is not in deps
        // Property 'completed' does not exist on type 'Pick<Todo, "id" | "title">'
        <span>{todo.completed}</span>
      ))}
    </ul>
  );
}

This ensures that your component's dependencies are always in sync with what you actually use, preventing subtle bugs where you forget to add a property to deps.

When to Use Zeiger

Zeiger is particularly useful when:

  • You have large collections where items update frequently
  • Different components need different properties from the same collection
  • You want to optimize list rendering performance
  • You need to select individual items by ID without re-rendering the entire list

License

MIT