1k-state-management
Provides patterns for managing application state with Jotai, including atoms, context, and data persistence.
Install
mkdir -p .claude/skills/1k-state-management && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/1745" && unzip -o skill.zip -d .claude/skills/1k-state-management && rm skill.zipInstalls to .claude/skills/1k-state-management
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Jotai state management patterns — atoms, globalAtom, contextAtom, and persistence.Key capabilities
- →Define global atoms for persistent app-wide state
- →Create context-specific atoms for feature-level state
- →Implement state persistence with local storage
- →Standardize state operations using actions and hooks
How it works
It enforces a strict directory-based architecture where global state resides in kit-bg and feature-specific state is managed via context providers.
Inputs & outputs
When to use 1k-state-management
- →Define global atoms for shared state
- →Implement state persistence with local storage
- →Create context-specific Jotai providers
- →Refactor complex state into derived atoms
About this skill
OneKey State Management
Jotai Atom Organization - MANDATORY STRUCTURE
Global State Atoms (for app-wide, persistent state)
- Location:
packages/kit-bg/src/states/jotai/atoms/ - Usage: Global settings, account state, hardware state, currency, etc.
- Pattern: Use
globalAtomandEAtomNamesfor standardization - Examples:
settings.ts,account.ts,hardware.ts,currency.ts
Feature-Specific State Atoms (for localized functionality)
- Location:
packages/kit/src/states/jotai/contexts/[feature_name]/atoms.ts - Usage: Feature-specific state that may be shared across components within that feature
- Pattern: Use
contextAtomfromcreateJotaiContextfor consistency - Structure:
contexts/ ├── marketV2/ │ ├── atoms.ts - State definitions │ ├── actions.ts - State operations │ └── index.ts - Exports ├── swap/ │ ├── atoms.ts │ ├── actions.ts │ └── index.ts
FORBIDDEN Atom Patterns
- ❌ NEVER create atom directories under
packages/kit/src/views/ - ❌ NEVER create standalone atom files in component directories
- ❌ NEVER mix
globalAtomandcontextAtompatterns without architectural justification
Atom Selection Guidelines
Use globalAtom when:
- State needs persistence across app restarts
- State is used across multiple major features
- State affects the entire application (settings, authentication, etc.)
- Located in
packages/kit-bg/src/states/jotai/atoms/
Use contextAtom when:
- State is specific to a feature or module
- State is temporary/session-based
- State is shared within related components of a feature
- Located in
packages/kit/src/states/jotai/contexts/[name]/atoms.ts
IMPORTANT: These are the ONLY two atom patterns used in the project. Do not create custom atom patterns or use plain Jotai atoms outside of these established structures.
Common Patterns
Creating a Global Atom
// packages/kit-bg/src/states/jotai/atoms/myFeature.ts
import { globalAtom } from '../utils';
import { EAtomNames } from '../atomNames';
export const myFeatureAtom = globalAtom<MyFeatureState>({
name: EAtomNames.myFeature,
initialValue: { /* initial state */ },
persist: true, // if persistence needed
});
Creating a Context Atom
// packages/kit/src/states/jotai/contexts/myFeature/atoms.ts
import { createJotaiContext } from '../../utils';
const { contextAtom, useContextAtom } = createJotaiContext();
export const myFeatureDataAtom = contextAtom<MyData | null>(null);
// Export hook for components
export { useContextAtom };
Using Atoms in Components
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import { myFeatureAtom } from '@onekeyhq/kit-bg/src/states/jotai/atoms';
function MyComponent() {
// Read and write
const [value, setValue] = useAtom(myFeatureAtom);
// Read only
const value = useAtomValue(myFeatureAtom);
// Write only
const setValue = useSetAtom(myFeatureAtom);
}
When not to use it
- →When creating standalone atom files in component directories
- →When mixing global and context patterns without justification
Prerequisites
Limitations
- →Forbidden from creating atom directories under views
- →Only two established atom patterns are permitted
How it compares
It replaces ad-hoc state management with a mandatory, standardized structure that prevents scattered atom definitions.
Compared to similar skills
1k-state-management side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| 1k-state-management (this skill) | 4 | 4mo | No flags | Intermediate |
| zustand | 113 | 2mo | No flags | Intermediate |
| react | 34 | 2mo | No flags | Intermediate |
| react-component-patterns | 3 | 29d | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by OneKeyHQ
View all by OneKeyHQ →You might also like
zustand
lobehub
Zustand state management guide. Use when working with store code (src/store/**), implementing actions, managing state, or creating slices. Triggers on Zustand store development, state management questions, or action implementation.
react
lobehub
React component development guide. Use when working with React components (.tsx files), creating UI, using @lobehub/ui components, implementing routing, or building frontend features. Triggers on React component creation, modification, layout implementation, or navigation tasks.
react-component-patterns
HoangNguyen0403
Modern React component architecture and composition patterns.
zustand-5
prowler-cloud
Zustand 5 state management patterns. Trigger: When implementing client-side state with Zustand (stores, selectors, persist middleware, slices).
react-router-getting-started
ssrjkk
Getting Started for React-Router: initial setup and first steps
accessibility-compliance
wshobson
Implement WCAG 2.2 compliant interfaces with mobile accessibility, inclusive design patterns, and assistive technology support. Use when auditing accessibility, implementing ARIA patterns, building for screen readers, or ensuring inclusive user experiences.