agentleFS
siberiacancodesiberiacancode/agent-skills/skills/react-hooks-best-practices/AGENTS.md

agent-skills / react-hooks-best-practices

AGENTS.md23 starsChanged 2 months agoMITView on GitHub

Version 1.0.0 siberiacancode August 2026 Note: This document is optimized for agents and LLMs writing React application code with hooks, creating custom hooks, and reviewing hook behavior. It groups guidance by DX, optimization, and logic. React hooks best practices for using hooks in React applications and designing custom hooks across DX, optimization, and logic. Use it for component hook usage, custom hook design, hook API review, feature-logic extraction, and hook correctness/performance checks. When a component owns complex feature logic, move…

The file

We split this AGENTS.md into the rules it gives an agent

5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When a component owns complex feature logic, move that logic into a custom hook.

    line 32
  2. Distinctive:

    Do not extract just to make a file shorter.

    line 34
  3. Very specific:

    Prefer grouped returns such as form, state, functions, refs, and features.

    line 36
  4. Very specific:

    Use the callback path for imperative side effects such as CSS variables, canvas drawing, analytics, or DOM measurements.

    line 46
  5. Very specific:

    Only call watch() at the usage site when JSX needs the live value.

    line 48

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

React Hooks Best Practices

Version 1.0.0
siberiacancode
August 2026

Note:
This document is optimized for agents and LLMs writing React application code with hooks, creating custom hooks, and reviewing hook behavior. It groups guidance by DX, optimization, and logic.


Abstract

React hooks best practices for using hooks in React applications and designing custom hooks across DX, optimization, and logic. Use it for component hook usage, custom hook design, hook API review, feature-logic extraction, and hook correctness/performance checks.


Table of Contents

  1. DX
    • 1.1 Extract complex feature logic into hooks
  2. Optimization
    • 2.1 Watch mode for hot updates
  3. Logic

1. DX

1.1 Extract complex feature logic into hooks

When a component owns complex feature logic, move that logic into a custom hook. This applies to forms, modals, mutations, routing, persistence, selected entities, derived values, and action handlers, even when there are no browser subscriptions.

Do not extract just to make a file shorter. Extract a cohesive feature scenario and expose a clear contract. Name the hook use + component/feature name, and name params types Use + component/feature name + Params, for example useCreateRoomForm and UseCreateRoomFormParams.

Prefer grouped returns such as form, state, functions, refs, and features; add domain-specific groups only when they make the component easier to read.

The component should read like UI composition. The hook should read like the feature controller.

2. Optimization

2.1 Watch mode for hot updates

For hooks that listen to hot external sources like mouse movement, scroll, observers, timers, or device sensors, do not force every update through React state. Keep the default path as callback + snapshot, and expose watch() as an explicit opt-in for components that actually render the value.

Use the callback path for imperative side effects such as CSS variables, canvas drawing, analytics, or DOM measurements. Throttling, debouncing, and requestAnimationFrame are consumer-side composition, not options baked into the primitive hook.

Only call watch() at the usage site when JSX needs the live value. One hook should support both modes: zero-render imperative usage by default, reactive rendering only when the consumer asks for it.

3. Logic

Rules coming soon.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.