All skills
siberiacancode avatar

/react-hooks-best-practices

@dc7ec6c

React hooks best practices for React application code and custom hook design across DX, optimization, and logic. Use when writing components with hooks, creating or refactoring custom hooks, reviewing hook usage/APIs/internals, checking effects/dependencies/state/refs/callbacks, or improving hook correctness, ergonomics, and performance.

Use this Skill: https://skilld.dev/gh/siberiacancode/agent-skills/react-hooks-best-practices

This session only. Nothing lands on disk.

AGENTS.md

≈634 tokens on demand. Your agent reads this file only when SKILL.md points to it.

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
  2. Optimization
  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.

Source: SKILL.md on GitHub

No alerts1mo3 checks · Risk SAFE
  • Gen Agent Trust Hub1mo

    This skill provides a set of architectural guidelines and performance best practices for using React Hooks. It consists entirely of documentation and code examples intended for developer guidance and contains no malicious code, hidden instructions, or security risks.

  • Socket1mo

    No alerts

  • Snyk1mo

    Risk: LOW · No issues

Signed by skilld at dc7ec6c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 2 months ago

README badge

README badge for siberiacancode/agent-skills/react-hooks-best-practices