recoil

Recoil 专家 — 帮助开发者在 React 应用中使用原子(共享状态单元)、选择器(派生/异步状态)和原子族来管理状态,提供基于图的状态模型,配合 React 并发特性以减少不必要的重新渲染并将异步数据获取作为一等状态处理。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "recoil":https://skillpi.com/zh/skills/deepskill-edeb80aea7a644bd773cb117ba5a9f8ce98b814576d30c8d7355df595b533124。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

Recoil 专家 — 帮助开发者在 React 应用中使用原子(共享状态单元)、选择器(派生/异步状态)和原子族来管理状态,提供基于图的状态模型,配合 React 并发特性以减少不必要的重新渲染并将异步数据获取作为一等状态处理。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: recoil
description: >-
  You are an expert in Recoil, the state management library by Meta for React
  applications. You help developers manage application state with atoms
  (shared state units), selectors (derived/async state), and atom families —
  providing a graph-based state model that integrates naturally with React's
  concurrent features, avoids unnecessary re-renders, and handles async data
  fetching as first-class state.
license: Apache-2.0
compatibility: ''
metadata:
  author: terminal-skills
  version: 1.0.0
  category: Frontend Development
  tags:
    - state-management
    - react
    - atoms
    - selectors
    - meta
    - async
    - graph

Recoil — State Management for React

You are an expert in Recoil, the state management library by Meta for React applications. You help developers manage application state with atoms (shared state units), selectors (derived/async state), and atom families — providing a graph-based state model that integrates naturally with React's concurrent features, avoids unnecessary re-renders, and handles async data fetching as first-class state.

Core Capabilities

Atoms and Selectors

import { atom, selector, useRecoilState, useRecoilValue, RecoilRoot } from "recoil";

// Atoms — units of state
const todosAtom = atom<Todo[]>({
  key: "todos",
  default: [],
});

const filterAtom = atom<"all" | "active" | "completed">({
  key: "todoFilter",
  default: "all",
});

// Selectors — derived state (auto-updates when dependencies change)
const filteredTodosSelector = selector({
  key: "filteredTodos",
  get: ({ get }) => {
    const todos = get(todosAtom);
    const filter = get(filterAtom);
    switch (filter) {
      case "active": return todos.filter((t) => !t.done);
      case "completed": return todos.filter((t) => t.done);
      default: return todos;
    }
  },
});

const statsSelector = selector({
  key: "todoStats",
  get: ({ get }) => {
    const todos = get(todosAtom);
    return {
      total: todos.length,
      completed: todos.filter((t) => t.done).length,
      percent: todos.length ? Math.round(todos.filter((t) => t.done).length / todos.length * 100) : 0,
    };
  },
});

// Components
function TodoList() {
  const filteredTodos = useRecoilValue(filteredTodosSelector);  // Only re-renders when filtered list changes
  return (
    <ul>
      {filteredTodos.map((todo) => <TodoItem key={todo.id} id={todo.id} />)}
    </ul>
  );
}

function TodoStats() {
  const stats = useRecoilValue(statsSelector);
  return <p>{stats.completed}/{stats.total} done ({stats.percent}%)</p>;
}

function FilterButtons() {
  const [filter, setFilter] = useRecoilState(filterAtom);
  return (
    <div>
      {(["all", "active", "completed"] as const).map((f) => (
        <button key={f} onClick={() => setFilter(f)}
          style={{ fontWeight: filter === f ? "bold" : "normal" }}>
          {f}
        </button>
      ))}
    </div>
  );
}

function App() {
  return (
    <RecoilRoot>
      <TodoStats />
      <FilterButtons />
      <TodoList />
    </RecoilRoot>
  );
}

Async Selectors and Atom Families

// Async selector — fetches data, integrates with Suspense
const userProfileSelector = selector({
  key: "userProfile",
  get: async ({ get }) => {
    const userId = get(currentUserIdAtom);
    const response = await fetch(`/api/users/${userId}`);
    return response.json();
  },
});

// Atom families — parameterized atoms (one atom per ID)
const todoItemAtom = atomFamily<Todo | null, string>({
  key: "todoItem",
  default: null,
});

// Selector families — parameterized selectors
const userByIdSelector = selectorFamily<User, string>({
  key: "userById",
  get: (userId) => async ({ get }) => {
    const response = await fetch(`/api/users/${userId}`);
    return response.json();
  },
});

// Usage with Suspense
function UserProfile() {
  const profile = useRecoilValue(userProfileSelector);  // Suspends until loaded
  return <h1>{profile.name}</h1>;
}

function App() {
  return (
    <RecoilRoot>
      <Suspense fallback={<Spinner />}>
        <UserProfile />
      </Suspense>
    </RecoilRoot>
  );
}

Installation

npm install recoil

Best Practices

  1. Unique keys — Every atom and selector needs a globally unique key string; use descriptive names
  2. Selectors for derived state — Never compute derived state in components; use selectors for memoized computation
  3. Atom families — Use atomFamily for collections (todo items, user profiles); one atom per entity
  4. Async selectors — Return promises from selector get; pairs with React Suspense for loading states
  5. Fine-grained atoms — Prefer many small atoms over one large one; minimizes re-renders
  6. RecoilRoot — Wrap app once; provides state context; can nest for isolated state subtrees
  7. useRecoilValue — Use when you only read; useRecoilState when you also write; avoids unnecessary subscriptions
  8. Concurrent mode — Recoil is designed for React concurrent features; async selectors work with Suspense transitions

当前收录版本

1.0.0

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值92/100

亮点

  • 提供了 Recoil 状态管理库的完整核心概念和使用方法
  • 包含 atoms、selectors、atom families 等关键特性的实用示例
  • 覆盖了异步数据获取和 React Suspense 集成等高级用法
触发精准95/100

亮点

  • 触发描述精准完整,明确指出了 Recoil 专家角色
  • 覆盖了 atoms、selectors、async state 等核心概念关键词
  • 边界清晰,不会与其他状态管理库混淆
结构规范90/100

亮点

  • 文档结构清晰,有完整的使用示例和最佳实践
  • frontmatter 信息完整,包含作者、版本、分类等元数据
  • 代码示例完整且可直接运行
执行可靠90/100

亮点

  • 代码示例参数正确,语法规范
  • 覆盖了主要异常处理场景
  • 提供了完整的安装和使用说明
证据可验 (前四项均值)92/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

  • 安装或获取外部依赖

    使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。

    主文档提及 · 第 162 行

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。