About valtio-define
valtio-define is a Valtio-based state management library for React developers. It creates reactive stores with state, actions, and getters through a Pinia-like API, with TypeScript support.
Key features
- 01Reactive store factory
- 02State, actions, and getters
- 03React hook for store access
- 04State subscriptions and patches
- 05Plugins and persistent state
Use cases
- 01Organizing shared React application state
- 02Subscribing to store changes
- 03Persisting state through a plugin
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ hairyf/ skills --skill valtio-defineAfter installing, type/valtio-definein Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
LICENSE.mdSYNC.mdreferences/advanced-patch.mdadvanced-signal.mdadvanced-store-to-state.mdadvanced-subscribe.mdcore-define-store.mdcore-types.mdcore-use-store.mdfeature-persistent-plugin.mdfeature-plugin-system.mdDetails
From the project READMEBased 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
| Topic | Description | Reference |
|---|---|---|
| defineStore | Core API for creating reactive stores | core-define-store |
| useStore | React hook for accessing store state | core-use-store |
| Types | TypeScript types and interfaces | core-types |
Advanced Features
| Topic | Description | Reference |
|---|---|---|
| Subscriptions | Subscribe to state changes | advanced-subscribe |
| Patch | Update state with patch operations | advanced-patch |
| Signal | JSX component for inline reactive values | advanced-signal |
| Store to State | Convert store to useState-like hooks | advanced-store-to-state |
Features
| Topic | Description | Reference |
|---|---|---|
| Plugin System | Extend stores with plugins | feature-plugin-system |
| Persistent Plugin | Persist state to storage | feature-persistent-plugin |
Quick Start
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>
)
}
Comments
Markdown supported