recoil
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "recoil" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-edeb80aea7a644bd773cb117ba5a9f8ce98b814576d30c8d7355df595b533124. Verify the upstream source and version against https://github.com/TerminalSkills/skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
github.com
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Recoil expert — Help developers manage state in React apps using atoms (shared state units), selectors (derived/asynchronous state) and atom families, providing a graph-based state model that integrates with React concurrent features to avoid unnecessary rerenders and treat asynchronous data fetching as first-class state.
Introduction source: third_party · TerminalSkills · 1.0.0 Reference
SkillPi interpretation
- Testing
- Not tested
Browse files
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
- graphRecoil — 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
- Unique keys — Every atom and selector needs a globally unique
keystring; use descriptive names - Selectors for derived state — Never compute derived state in components; use selectors for memoized computation
- Atom families — Use
atomFamilyfor collections (todo items, user profiles); one atom per entity - Async selectors — Return promises from selector
get; pairs with React Suspense for loading states - Fine-grained atoms — Prefer many small atoms over one large one; minimizes re-renders
- RecoilRoot — Wrap app once; provides state context; can nest for isolated state subtrees
- useRecoilValue — Use when you only read;
useRecoilStatewhen you also write; avoids unnecessary subscriptions - Concurrent mode — Recoil is designed for React concurrent features; async selectors work with Suspense transitions
Current listing version
1.0.0
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供了 Recoil 状态管理库的完整核心概念和使用方法
- 包含 atoms、selectors、atom families 等关键特性的实用示例
- 覆盖了异步数据获取和 React Suspense 集成等高级用法
Highlights
- 触发描述精准完整,明确指出了 Recoil 专家角色
- 覆盖了 atoms、selectors、async state 等核心概念关键词
- 边界清晰,不会与其他状态管理库混淆
Highlights
- 文档结构清晰,有完整的使用示例和最佳实践
- frontmatter 信息完整,包含作者、版本、分类等元数据
- 代码示例完整且可直接运行
Highlights
- 代码示例参数正确,语法规范
- 覆盖了主要异常处理场景
- 提供了完整的安装和使用说明
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 162
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.