nstate

Provides expertise on the `nstate` library, a high-performance React state management tool. Use this for questions about store creation, Immer-based updates, `useBind` for forms, `useSubStore` for state slicing, and combining multiple stores.

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "nstate" with this command: npx skills add zaaack/prompts/zaaack-prompts-nstate

nstate

nstate is a high-performance React state management library designed for low mental overhead. It features auto-binding, built-in Immer support for immutable updates, and powerful store composition.

Key API Methods

MethodDescription
setState(patch)Updates state via object, updater function, or Immer draft.
useState(getter)React hook to subscribe to specific state slices.
useWatch(getter, handler)Watches state changes and triggers side effects; auto-cleans on unmount.
useBind(getter)Two-way binding for form inputs with type safety.
useSubStore(getter, setter)Creates a synchronized "view" of a parent store's slice.
useLocalStore(initial, actions)Creates a localized store instance within a component.

Practical Examples

1. The Class-Based Store (Recommended)

Encapsulate logic by extending the NState class.

import NState from 'nstate';

interface CounterState { count: number }

export class CounterStore extends NState<CounterState> {
  inc = () => this.setState(s => ({ count: s.count + 1 }));

  // Using Immer draft
  reset = () => this.setState(draft => { draft.count = 0; });
}

export const counterStore = new CounterStore({ count: 0 });

2. Form Binding with useBind

Eliminate boilerplate onChange handlers while maintaining type safety.

function ProfileEditor() {
  const bind = store.useBind(s => s.user);
  return (
    <input type="text" {...bind('name')} />
    /* Automatically handles value and onChange */
  );
}

3. Store Composition

You can link stores together using the watch API inside onInit.

export class RootStore extends NState<GlobalState> {
  child = new ChildStore({ data: '' });

  onInit() {
    this.child.watch(s => s.data, (val) => {
      console.log("Child store updated global effect:", val);
    });
  }
}

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

keyv-browser

No summary provided by upstream source.

Repository SourceNeeds Review
General

keyv-file

No summary provided by upstream source.

Repository SourceNeeds Review
General

create-skill

No summary provided by upstream source.

Repository SourceNeeds Review
General

PromptVault Team Prompt Library

Organize, rate, and share prompts with your team. Never lose a great prompt again. Centralized prompt management with search, tags, and ratings.

Registry SourceRecently Updated
710Profile unavailable