react-effect-decision

Combine React's official "You Might Not Need an Effect" guidance with this project's stricter no direct useEffect stance. Use when writing, reviewing, or refactoring React components that might reach for useEffect, derived state, event relays, reset logic, subscriptions, or client fetching.

6 stars

Best use case

react-effect-decision is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Combine React's official "You Might Not Need an Effect" guidance with this project's stricter no direct useEffect stance. Use when writing, reviewing, or refactoring React components that might reach for useEffect, derived state, event relays, reset logic, subscriptions, or client fetching.

Teams using react-effect-decision should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/react-effect-decision/SKILL.md --create-dirs "https://raw.githubusercontent.com/get-convex/components-submissions-directory/main/.claude/skills/react-effect-decision/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/react-effect-decision/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How react-effect-decision Compares

Feature / Agentreact-effect-decisionStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Combine React's official "You Might Not Need an Effect" guidance with this project's stricter no direct useEffect stance. Use when writing, reviewing, or refactoring React components that might reach for useEffect, derived state, event relays, reset logic, subscriptions, or client fetching.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# React effect decision

Default rule for this project: do not reach for direct `useEffect` first.

Most effect usage in React code is a sign that the component is syncing state that should be derived during render, routing an event through state, or resetting local state in a way React already models better.

This skill merges:

* React's official decision tree from "You Might Not Need an Effect"
* The project's stricter no direct `useEffect` preference

## Start here

Before writing any effect, ask these in order:

1. Can I calculate this from props or state during render
2. Is this triggered by a user action and better placed in the event handler
3. Am I trying to reset component state when identity changed and should use `key`
4. Is this an expensive pure calculation that should use `useMemo`
5. Is this an external subscription that should use `useSyncExternalStore` or a focused custom hook
6. Is this real external synchronization that must happen on mount or on dependency changes

If you answer yes to any of 1 through 5, do not write a direct `useEffect`.

## Project stance

React allows effects for real external synchronization. This project is stricter:

* Avoid direct `useEffect` in components whenever a clearer pattern exists
* Prefer derived values, event handlers, `key` remounts, memoization, query libraries, Convex hooks, and focused custom hooks
* If mount only external setup is truly needed, use an explicit `useMountEffect` wrapper instead of sprinkling raw `useEffect` through feature code

Example wrapper:

```ts
import { useEffect } from "react";

export function useMountEffect(effect: () => void | (() => void)) {
  useEffect(effect, []);
}
```

Use that only for one time external setup like DOM focus, third party widgets, or browser API listeners that belong to the component lifecycle.

## Decision guide

### 1. Derived state belongs in render

Bad smell:

* `useEffect(() => setX(deriveFromY(y)), [y])`
* State that only mirrors props or other state

Do this instead:

```tsx
function TodoList({ todos, showActive }: Props) {
  const activeTodos = todos.filter((todo) => !todo.completed);
  const visibleTodos = showActive ? activeTodos : todos;

  return <List items={visibleTodos} />;
}
```

If it can be calculated from existing inputs, keep it out of state.

### 2. Expensive pure calculations use `useMemo`

If the calculation is pure and expensive, memoize it instead of syncing it into state:

```tsx
const visibleTodos = useMemo(
  () => getVisibleTodos(todos, showActive),
  [todos, showActive],
);
```

Use memoization only when there is real repeated work to skip.

### 3. Event caused work belongs in the event handler

Bad smell:

* Set a flag in state
* Wait for an effect to notice the flag
* Reset the flag after the side effect runs

Do this instead:

```tsx
function PurchaseButton({ product }: Props) {
  async function handleClick() {
    await addToCart(product);
    showNotification(`Added ${product.name}`);
  }

  return <button onClick={handleClick}>Buy</button>;
}
```

If the work happens because the user clicked, submitted, dragged, or selected, keep it in the handler.

### 4. Reset with `key`, not effect choreography

Bad smell:

* `useEffect(() => setFormState(initialFromProps), [id])`

Do this instead:

```tsx
function EditContact({ contact, onSave }: Props) {
  return <EditContactForm key={contact.id} contact={contact} onSave={onSave} />;
}
```

If a different entity should feel like a fresh component instance, give the inner component a `key`.

### 5. Adjusting state from prop changes is a last resort

If you cannot derive it and do not want a full remount, adjust the state during render of the same component before children render stale data.

Prefer these, in order:

1. Derive it
2. Reset with `key`
3. Store an ID and derive the selected object from current inputs
4. Only then use a guarded render time adjustment pattern

### 6. Data fetching should use the app's data layer or a focused hook

Bad smell:

* Raw `fetch(...).then(setState)` inside a component effect
* Manual loading, retry, cancellation, and stale response handling in feature code

Preferred options:

* Use Convex React hooks where the data already lives in Convex
* Use the project's existing data abstraction or a query library for remote APIs
* If raw client fetching is unavoidable, isolate it inside a custom hook and handle stale response cleanup

Example custom hook pattern:

```tsx
function useSearchResults(url: string) {
  const [data, setData] = useState<Result[] | null>(null);

  useEffect(() => {
    let ignore = false;

    fetch(url)
      .then((response) => response.json())
      .then((json) => {
        if (!ignore) {
          setData(json);
        }
      });

    return () => {
      ignore = true;
    };
  }, [url]);

  return data;
}
```

That is still less preferred than a dedicated query layer, but better than scattering raw fetch effects across components.

### 7. External subscriptions should use `useSyncExternalStore`

For browser or third party stores, prefer the React built in subscription model:

```tsx
function useOnlineStatus() {
  return useSyncExternalStore(
    subscribe,
    () => navigator.onLine,
    () => true,
  );
}
```

This is clearer and safer than mirroring an external mutable source through ad hoc effect code.

### 8. True external synchronization is the narrow allowed case

An effect or `useMountEffect` is appropriate when the component must synchronize with something outside React:

* DOM focus or scroll positioning
* Third party widget setup and cleanup
* Browser API subscriptions
* Network synchronization that should happen because the component is on screen, not because a user event fired

When you use one, document the external system in a comment or nearby helper.

## Quick smell test

If you are about to write `useEffect`, check:

* Is this just derived state
* Is this event specific logic
* Is this a reset that should use `key`
* Is this a pure expensive calculation
* Is this a subscription better modeled with `useSyncExternalStore`
* Is this data loading that belongs in Convex, a query library, or a custom hook
* What external system am I synchronizing with

If you cannot name the external system, you probably do not need an effect.

## Code review prompts

Use these during review:

* What breaks if this effect is removed and the value is derived during render
* Is this component storing data that can be recomputed from props or state
* Why is this work not in the click, submit, or change handler that caused it
* Would `key={entityId}` remove the reset logic entirely
* Should this be a custom hook instead of inline effect code
* Is this component talking to an external system, or only to React state

## Summary

The safest path in this repo is simple:

* Derive during render when possible
* Handle user caused work in handlers
* Reset with `key`
* Memoize expensive pure work
* Use dedicated hooks for fetching and subscriptions
* Reserve effect style lifecycle code for real external synchronization

Sources:

* [React docs: You Might Not Need an Effect](https://react.dev/learn/you-might-not-need-an-effect)

Related Skills

workos-convex-debug

6
from get-convex/components-submissions-directory

Debug and troubleshoot WorkOS AuthKit authentication issues with Convex. Use when authentication fails, JWT validation errors occur, user identity returns null, email claims are missing, admin access checks fail, or sign in button does not work. Supports Netlify deployment.

workos-convex-auth

6
from get-convex/components-submissions-directory

Set up and configure WorkOS AuthKit authentication with Convex backend. Use when integrating AuthKit, configuring JWT providers, setting up environment variables, or implementing sign in and sign out flows with React and Vite. Supports Netlify deployment.

convex-scale-optimization

6
from get-convex/components-submissions-directory

Patterns for scaling read-heavy Convex apps to millions of users. Use when optimizing bandwidth, reducing query costs, fixing slow queries, creating digest tables, replacing reactive subscriptions with one-shot fetches, adding compound indexes, debouncing writes, rate-controlling backfills, or running npx convex insights. Trigger when users mention "scale", "bandwidth", "performance", "optimize", "slow queries", "expensive queries", "digest table", "denormalize", or "thundering herd" in the context of Convex.

convex-design-system

6
from get-convex/components-submissions-directory

Convex UI component patterns from the live Storybook preview. Use when building React components, forms, modals, navigation, feedback states, or app layouts that should match the current Convex design system. Applies to both shared primitives and dashboard style product UI.

Update project docs

6
from get-convex/components-submissions-directory

Sync project tracking files after completing work, then provide a ready to use git commit message.

typeset

6
from get-convex/components-submissions-directory

Improves typography by fixing font choices, hierarchy, sizing, weight, and readability so text feels intentional. Use when the user mentions fonts, type, readability, text hierarchy, sizing looks off, or wants more polished, intentional typography.

teach-impeccable

6
from get-convex/components-submissions-directory

One-time setup that gathers design context for your project and saves it to your AI config file. Run once to establish persistent design guidelines.

robel-auth

6
from get-convex/components-submissions-directory

Integrate and maintain Robelest Convex Auth in apps by always checking upstream before implementation. Use when adding auth setup, updating auth wiring, migrating between upstream patterns, or troubleshooting @robelest/convex-auth behavior across projects.

quieter

6
from get-convex/components-submissions-directory

Tones down visually aggressive or overstimulating designs, reducing intensity while preserving quality. Use when the user mentions too bold, too loud, overwhelming, aggressive, garish, or wants a calmer, more refined aesthetic.

polish

6
from get-convex/components-submissions-directory

Performs a final quality pass fixing alignment, spacing, consistency, and micro-detail issues before shipping. Use when the user mentions polish, finishing touches, pre-launch review, something looks off, or wants to go from good to great.

overdrive

6
from get-convex/components-submissions-directory

Pushes interfaces past conventional limits with technically ambitious implementations — shaders, spring physics, scroll-driven reveals, 60fps animations. Use when the user wants to wow, impress, go all-out, or make something that feels extraordinary.

optimize

6
from get-convex/components-submissions-directory

Diagnoses and fixes UI performance across loading speed, rendering, animations, images, and bundle size. Use when the user mentions slow, laggy, janky, performance, bundle size, load time, or wants a faster, smoother experience.