Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add rules/tonyghiani/ai-essentials/react-effects-dependenciesgit clone --depth 1 https://github.com/tonyghiani/ai-essentialsWhat it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5 | $0.00000 | $0.01042 |
| Opus 5 | $0.00000 | $0.00521 |
| Sonnet 5 | $0.00000 | $0.00208 |
| Haiku 4.5 | $0.00000 | $0.00104 |
Grade A, and why
react-effects-dependencies scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 101 lines — stays where its author put it; the contents beside it link to each section on GitHub.
You are an expert React developer. When generating code that uses useEffect and related APIs, follow these rules.
When to Use Event Handlers vs Effects
- Use event handlers for:
- Logic that should run only in direct response to user actions (click, submit, keydown, etc.).
- Sending analytics or POST requests for specific user interactions.
- Showing toasts or notifications from user actions.
- Do NOT:
- Toggle state and then use an effect to "react" to that state change for event-only logic.
- Chain multiple effects where each only exists to update state for another effect.
When to Use Effects
- Use effects to synchronize React with external systems:
- Network connections (websockets, subscriptions, streaming APIs).
- Browser APIs and event listeners.
- Non-React widgets and imperative DOM APIs controlled by React state/props.
- Data fetching tied to "what is currently rendered" when no better framework-level APIs exist.
- Structure:
- Setup external synchronization in the effect body.
- Return a cleanup function that fully undoes the setup.
Effect Purity and Cleanup
- Effects run after DOM commit, not during render:
- Never rely on them to compute values needed for immediate rendering.
- Always provide cleanup for:
- Subscriptions (unsubscribe/removeEventListener in cleanup).
- Async tasks (ignore stale results or abort requests in cleanup).
- External instances (disconnect/destroy on cleanup).
- Design effects so that:
- setup → cleanup → setup again is safe and idempotent.
- React Strict Mode double-mount in development does not break behavior.
Dependencies – Follow the Linter
- Always include all reactive values used in the effect in the dependency array:
- Reactive values: props, state, and variables/functions defined in the component body.
- Treat dependency warnings as errors:
- Do NOT disable the eslint-plugin-react-hooks rules.
- Fix the code instead of manually forcing dependency arrays.
- Values that can be safely omitted from dependencies:
- State setters returned by useState.
- The ref objects returned by useRef (NOT ref.current).
Refactoring to Reduce Dependencies
- To reduce unnecessary dependencies:
- Move constant, purely static values out of the component into module scope.
- Move object creation into the effect and depend on primitives instead of objects.
- Use functional setState updates to avoid capturing stale state:
- setValue(prev => computeNext(prev, input));
- Split effects by responsibility:
- If an effect does multiple unrelated things, break it into multiple effects with focused dependencies.
Avoid Misusing Effects
- Do NOT:
- Use effects for derived data; compute derived values during render.
- Use effects to "fix up" state after render when you can model the desired state directly.
- Use custom "lifecycle" hooks that hide or avoid dependencies (e.g., useEffectOnce, useMount) to bypass the linter.
Strict Mode Considerations
- Assume effects can run more than once in development:
- Never gate the effect with a ref flag just to avoid double execution.
- Rely on proper cleanup and idempotent setup instead.
Effect Events (useEffectEvent) – If Available
- When useEffectEvent is available:
- Use it to define non-reactive callbacks that:
- Need access to the latest props/state.
- Should NOT cause the effect to re-run when they change.
- Use it to define non-reactive callbacks that:
- Pattern:
- Put subscription setup/teardown in useEffect.
- Pass the Effect Event to the subscription as the callback.
- Do NOT:
- Pass Effect Events as props.
- Call Effect Events outside an effect context.
Data Fetching with Effects
- Prefer framework or library-level data APIs (Next.js data fetching, React Server Components, TanStack Query) over manual useEffect fetches.
- If using useEffect for fetching:
- Encapsulate logic in a custom hook (e.g., useData, useSearchResults).
- Handle race conditions:
- Use an ignore flag or AbortController to discard stale responses.
- Only re-fetch when relevant parameters (URL, query, page, filters) change.
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2d ago First seen · 101 lines · 0 tokens per session scan A c7efd4412033
react-effects-dependencies is a cursor rule published in the GitHub repository tonyghiani/ai-essentials (6 stars, last pushed 24d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,042 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other cursor rules, from other repositories
webkit-browser
Cursor rule "webkit-browser" from duckduckgo/apple-browsers, covering webkit & browser development guidelines, webview configuration, basic webview setup, user scripts management and tab management.
cypress-e2e-testing-cursorrules-prompt-file
Cursor rules for Cypress development with E2E testing.
vasu-playwright-utils
../../templates/cursor-rules/vasu-playwright-utils.mdc.
vla-registry
Multi-model GUI/VL registry — browser wllama grounding (ShowUI-2B is default + E2E gate).
dev-browser
Fallback browser automation with persistent Chrome state. Use only when Browser Use is unavailable or blocked.
node-dependencies
Enforce Node.js versioning and package management best practices.