Skip to content
Back to skills

Using React

ASecurity

Use when building or editing React 19+ components, hooks, or app routes. Triggers on `.tsx`/`.jsx` files with React imports, `'use client'` / `'use server'` directives, Server Components, form actions, useActionState, useOptimistic, use(), Suspense, or the React Compiler, even when the user doesn't say 'React'.

  • 6 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 30, 2026
ai-agentstypescriptgoreactapiperformance

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 18 files and shows the line behind each finding

Scanned November 30, 2026

npx -y skills add xonovex/platform --skill using-react --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Using React?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Using React
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/xonovex-using-react/badge)](https://www.skillsdirectory.com/skills/xonovex-using-react)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: using-react
description: "Use when building or editing React 19+ components, hooks, or app routes. Triggers on `.tsx`/`.jsx` files with React imports, `'use client'` / `'use server'` directives, Server Components, form actions, useActionState, useOptimistic, use(), Suspense, or the React Compiler, even when the user doesn't say 'React'."
---

# React Coding Guidelines

Build React interfaces with focused components, explicit state ownership, and predictable effects.

## Requirements

- React ≥ 19, Vite ≥ 6, Tailwind ≥ 4, Headless UI.

## React 19 Essentials

- **Server-first** - Components run on server by default; add `'use client'` only for interactivity
- **Form Actions** - Use `useActionState` and `FormData` instead of controlled inputs
- **Native metadata** - Use `<title>`, `<meta>`, `<link>` anywhere, auto-hoisted to `<head>`

## Quick Reference

| Feature | React 18 | React 19+ |
| --- | --- | --- |
| Memoization | Manual (`useMemo`, `useCallback`) | React Compiler (automatic) |
| Forward refs | `forwardRef()` wrapper | `ref` as regular prop |
| Context provider | `<Context.Provider value={}>` | `<Context value={}>` |
| Form state | Custom `useState` | `useActionState` hook |
| Optimistic updates | Manual state | `useOptimistic` hook |
| Read promises | Not possible | `use()` hook |
| Conditional context | Not possible | `use(Context)` after conditionals |
| Form pending | Manual tracking | `useFormStatus` hook |

## Example

```tsx
// React 19 Form with Actions
"use client";

import {useActionState} from "react";

function ContactForm() {
  const [state, formAction, isPending] = useActionState(
    async (prev, formData) => {
      const result = await submitForm(Object.fromEntries(formData));
      if (result.error) return {error: result.error};
      return {success: true};
    },
    null,
  );

  return (
    <form action={formAction}>
      <input name="email" type="email" disabled={isPending} />
      <button disabled={isPending}>
        {isPending ? "Submitting..." : "Submit"}
      </button>
      {state?.error && <p className="error">{state.error}</p>}
    </form>
  );
}

// ref as prop (no forwardRef needed)
function Input({ref, ...props}: {ref?: React.Ref<HTMLInputElement>}) {
  return <input ref={ref} {...props} />;
}

// Context as provider
const ThemeContext = createContext("light");

function App({children}) {
  return <ThemeContext value="dark">{children}</ThemeContext>;
}
```

## Essentials

- **Component design** - Small, composable; lift/minimize state; derive when possible, see [references/component-design.md](references/component-design.md)
- **Performance** - `memo()`, `lazy()` code-splitting, Server Components for FCP/SEO, see [references/performance-optimization.md](references/performance-optimization.md)
- **Rendering** - Prefer Server Components; use Suspense for streaming, see [references/suspense-streaming.md](references/suspense-streaming.md)
- **Accessibility** - Semantic HTML, ARIA, keyboard/focus management, see [references/accessibility.md](references/accessibility.md)
- **Custom hooks** - Extract reusable logic, see [references/hooks.md](references/hooks.md)

## Gotchas

- Stale closures in `useEffect`: captured state from the render that scheduled the effect, not the current state; use refs or include in deps
- List keys must be stable AND unique: index keys cause re-mounts on reorder, generated keys cause re-mounts every render
- `useMemo`/`useCallback` aren't free. The comparison + bookkeeping costs more than re-running cheap computations
- Controlled vs uncontrolled inputs: passing `value` without `onChange` warns; switching mid-lifetime is silently buggy
- Server Components can't use state/effects/event handlers. The boundary is `'use client'`; mis-marking causes runtime errors only

## Progressive Disclosure

### Guidelines

- Read [references/component-design.md](references/component-design.md) - Load when breaking down large components or managing state lifting
- Read [references/state-management.md](references/state-management.md) - Load when choosing between useState, useReducer, or Context
- Read [references/performance-optimization.md](references/performance-optimization.md) - Load when components re-render unnecessarily or performance lags
- Read [references/hooks.md](references/hooks.md) - Load when extracting reusable logic or creating custom hooks
- Read [references/accessibility.md](references/accessibility.md) - Load when adding keyboard navigation or screen reader support
- Read [references/new-hooks.md](references/new-hooks.md) - Load when using useActionState, useOptimistic, use(), or useFormStatus
- Read [references/server-components.md](references/server-components.md) - Load when building with RSC, Server Actions, or 'use server'/'use client' directives
- Read [references/suspense-streaming.md](references/suspense-streaming.md) - Load when using Suspense boundaries, streaming, or error handling
- Read [references/react-compiler.md](references/react-compiler.md) - Load when setting up or configuring the React Compiler
- Read [references/activity-effect-event.md](references/activity-effect-event.md) - Load when using Activity component or useEffectEvent

### Migration from React 18

- Read [references/migration-anti-patterns.md](references/migration-anti-patterns.md) - Load when adapting the React 18→19 mental model or avoiding outdated patterns (useEffect for data, manual loading states)
- Read [references/migration-deprecations.md](references/migration-deprecations.md) - Load when migrating from React 18 or handling removed APIs
- Read [references/migration-typescript.md](references/migration-typescript.md) - Load when fixing TypeScript errors after React 19 upgrade

Files in this skill

  • SKILL.md5.6 KB
  • eval-output.json3.1 KB
  • eval-trigger.json5.4 KB
  • moon.yml86 B
  • references/accessibility.md1.2 KB
  • references/activity-effect-event.md1.4 KB
  • references/component-design.md972 B
  • references/hooks.md1.4 KB
  • references/migration-anti-patterns.md1.4 KB
  • references/migration-deprecations.md1.3 KB
  • references/migration-typescript.md2.7 KB
  • references/new-hooks.md2.8 KB
  • references/performance-optimization.md1.1 KB
  • references/react-compiler.md458 B
  • references/server-components.md2.7 KB
  • references/state-management.md1.6 KB
  • references/suspense-streaming.md1.3 KB
  • sources.json1014 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.