AgentSkillsCN

jotai-reactive-atoms

在 Electron 渲染进程中,使用 Jotai 原子实现响应式状态管理。当你需要创建带有实时 IPC 更新的原子,或结合混合流与 HTTP 模式时,此技能将为你提供专业支持。

SKILL.md
--- frontmatter
name: jotai-reactive-atoms
description: Implement reactive state management with Jotai atoms in Electron renderer. Use when creating atoms with real-time IPC updates or hybrid stream + HTTP patterns.
allowed-tools: Read, Write, Edit, Grep, Glob

Jotai Reactive Atoms

Patterns

PatternUse CaseDetails
Hybrid AtomReal-time + HTTP fallbackHYBRID-ATOM.md
Stream AtomIPC subscriptionsEVENT-SUBSCRIPTION.md
Write AtomCRUD mutationsWRITE-ATOM.md

Key Rules

  1. Hybrid atom getter must NOT be async - use sync conditional
  2. Always debounce IPC handlers - prevent UI thrashing
  3. Refresh read atoms after mutations - set(singleFetchAtom)

Quick Example

typescript
// Hybrid selector (sync, NOT async)
export const usersAtom = atom((get) => {
  const stream = get(streamAtom);
  return stream !== undefined ? stream.value : get(singleFetchAtom);
});

Related