1K

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.zip

Installs 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.
82 charsno explicit “when” trigger
Intermediate

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

You give it
State definition and initial values
You get back
Reusable atoms and state management hooks

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 globalAtom and EAtomNames for 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 contextAtom from createJotaiContext for 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 globalAtom and contextAtom patterns 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

Jotai libraryProject-specific directory structure

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.

SkillInstallsUpdatedSafetyDifficulty
1k-state-management (this skill)44moNo flagsIntermediate
zustand1132moNo flagsIntermediate
react342moNo flagsIntermediate
react-component-patterns329dNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

Search skills

Search the agent skills registry