valtio-define

Original🇺🇸 English
Translated

Comprehensive skills for working with valtio-define

6installs
Added on

NPX Install

npx skill4agent add hairyf/skills valtio-define
Based on valtio-define v1.0.1. A Valtio-based state management library with Pinia-like API for React applications.

Overview

valtio-define provides a factory function for creating reactive stores with state, actions, and getters. Built on top of Valtio, it offers a familiar API similar to Pinia with full TypeScript support.

Core References

TopicDescriptionReference
defineStoreCore API for creating reactive storescore-define-store
useStoreReact hook for accessing store statecore-use-store
TypesTypeScript types and interfacescore-types

Advanced Features

TopicDescriptionReference
SubscriptionsSubscribe to state changesadvanced-subscribe
PatchUpdate state with patch operationsadvanced-patch
SignalJSX component for inline reactive valuesadvanced-signal
Store to StateConvert store to useState-like hooksadvanced-store-to-state

Features

TopicDescriptionReference
Plugin SystemExtend stores with pluginsfeature-plugin-system
Persistent PluginPersist state to storagefeature-persistent-plugin

Quick Start

tsx
import { defineStore, useStore } from 'valtio-define'

const store = defineStore({
  state: () => ({ count: 0 }),
  actions: {
    increment() { this.count++ },
  },
  getters: {
    doubled() { return this.count * 2 },
  },
})

function Counter() {
  const state = useStore(store)
  return (
    <div>
      <div>Count: {state.count}</div>
      <div>Doubled: {state.doubled}</div>
      <button onClick={store.increment}>Increment</button>
    </div>
  )
}