no-use-effect
ALWAYS ACTIVE. Enforces a strict no-direct-useEffect rule in React and React Native code. Never write useEffect directly — use derived state, event handlers…
от alejandrobailo★ 71 звезда на GitHub
Установить no-use-effect в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
No Direct useEffect
Never call useEffect directly. For the rare case of syncing with an external system on mount, use useMountEffect().
export function useMountEffect(effect: () => void | (() => void)) {
/* eslint-disable react-hooks/exhaustive-deps, no-restricted-syntax */
useEffect(effect, []);
}
The only place useEffect may appear directly is inside reusable custom hooks (like useMountEffect itself, or a useData hook when no fetching library is available). Components must never import or call useEffect.
React Compiler Projects
Before reaching for manual memoization, check whether the project compiles with React Compiler: reactCompiler: true in next.config.*, babel-plugin-react-compiler in package.json, or project rules that ban useMemo/useCallback.
When the compiler is on:
- Never write
useMemooruseCallback. The compiler memoizes derived values and functions for you. - Derive expensive values inline (Rule 1) and write callback refs as plain functions.
- Project rules about memoization win over the examples in this skill.
Without the compiler, the useMemo and useCallback examples below apply as written.
The 6 Rules
Rule 1: Derive state, do not sync it
If you can calculate it from existing state/props, compute it inline.
// BAD: two render cycles
const [filteredProducts, setFilteredProducts] = useState([]);
useEffect(() => {
setFilteredProducts(products.filter((p) => p.inStock));
}, [products]);
// GOOD: one render
const filteredProducts = products.filter((p) => p.inStock);
For expensive calculations without React Compiler, use useMemo:
const visibleTodos = useMemo(
() => getFilteredTodos(todos, filter),
[todos, filter]
);
With React Compiler, keep it inline. The compiler caches it:
const visibleTodos = getFilteredTodos(todos, filter);
Smell test: You're about to write useEffect(() => setX(f(y)), [y]) or state that only mirrors other state/props.
Rule 2: Use data-fetching libraries
Effect-based fetching creates race conditions and reinvents caching.
// BAD: race condition
useEffect(() => {
fetchProduct(productId).then(setProduct);
}, [productId]);
// GOOD: library handles cancellation/caching/staleness
const { data: product } = useQuery(
['product', productId],
() => fetchProduct(productId)
);
In React 19+, use the use() hook with <Suspense> to unwrap promises without useEffect or useState:
// GOOD: use() + Suspense (React 19+)
function UserProfile({ userPromise }: { userPromise: Promise<User> }) {
const user = use(userPromise);
return <h1>{user.name}</h1>;
}
Smell test: Your effect does fetch() then setState(), or you're reimplementing caching/retries/cancellation.
Rule 3: Event handlers, not effects
If a user action triggers it, do the work in the handler. Procedural logic (validate → transform → submit) belongs in handlers. Reconstructing procedural flow through ref+effect chains is a sign the logic was event-driven from the start.
// BAD: flag-relay through effect
const [liked, setLiked] = useState(false);
useEffect(() => {
if (liked) { postLike(); setLiked(false); }
}, [liked]);
// GOOD: direct
<button onClick={() => postLike()}>Like</button>
For shared logic between handlers, extract a function — not an effect:
function buyProduct() {
addToCart(product);
showNotification(`Added ${product.name}`);
}
Smell test: State used as a flag so an effect can do the real action, or "set flag -> effect runs -> reset flag" mechanics.
Rule 4: useMountEffect for one-time external sync
Only for true mount-time external system setup: DOM integration, third-party widgets, browser API subscriptions.
// BAD: guard inside effect
useEffect(() => {
if (!isLoading) playVideo();
}, [isLoading]);
// GOOD: conditional mounting
function VideoPlayerWrapper({ isLoading }) {
if (isLoading) return <LoadingScreen />;
return <VideoPlayer />;
}
function VideoPlayer() {
useMountEffect(() => playVideo());
}
Smell test: Behavior is naturally "setup on mount, cleanup on unmount" with an external system.
Rule 5: Reset with key, not dependency choreography
If you need "start fresh when ID changes," use React's remount semantics.
// BAD: effect resets on ID change
useEffect(() => { loadVideo(videoId); }, [videoId]);
// GOOD: key forces clean remount
<VideoPlayer key={videoId} videoId={videoId} />
function VideoPlayer({ videoId }) {
useMountEffect(() => { loadVideo(videoId); });
}
This also applies to resetting form state, clearing selections, etc. Use key on the component instead of an effect that sets state to initial values.
Smell test: Effect's only job is to reset local state when an ID/prop changes.
Rule 6: Never patch a broken effect with a ref
If you need a useRef to stop an effect from double-firing, looping, or accessing stale state, the eff
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- README.md
FAQ
Что делает скилл no-use-effect?
ALWAYS ACTIVE. Enforces a strict no-direct-useEffect rule in React and React Native code. Never write useEffect directly — use derived state, event handlers, useSyncExternalStore, data-fetching libraries or use(), key-based resets, or useMountEffect instead. React Compiler aware: no useMemo/useCallback when the compiler is on. Triggers on all React component code: writing new components, editing existing ones, reviewing code, fixing bugs, or refactoring. Also triggers when user mentions useEffect, side effects, data fetching, state sync, or component lifecycle.
Как установить скилл no-use-effect?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл no-use-effect запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
AnthropicCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
discernment-nudge
AnthropicAfter you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
data-consolidate
AnthropicJoins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
inspection-to-capa
AnthropicRuns the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…