agentleFS
sparrowbgsparrowbg/agent-skills/skills/react19/SKILL.md

react19

Skill0 starsChanged 7 months agoMITView on GitHub

Write modern React 19+ code using the latest hooks, APIs, and patterns. ALWAYS load this skill when the user mentions "react", "react 19", "hooks", "components", "jsx", "tsx", "useEffect", "useState", "context", "suspense", "forms", "optimistic UI", "transitions", or any client-side React work. Also trigger for: component design, state management, async UI patterns, form handling, ref usage, memoization, and React performance. TypeScript is always used unless the user explicitly says otherwise. This skill covers client-side React patterns only — for Next.js App Router, Server Components, or Server Actions, the nextjs skill applies instead.

  • Sends data out

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • one-ie/onetheir own version, first seen Jul 2, 2026
  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. one-ie/one★ 131same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository6 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

12 rules. About 0 are common, 6 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read promises and context in render — works conditionally, unlike hooks:

    line 144
  2. Distinctive:

    Never create promises inside render — creates a new promise on every render:

    line 173
  3. Very specific:

    Never add useEffectEvent functions to the dependency array

    line 205
  4. Distinctive:

    Only call them from inside Effects

    line 206
  5. Very specific:

    Don't remove existing useMemo/useCallback proactively — only when compiler is confirmed enabled.

    line 283
  6. Very specific:

    Use forwardRef — refs are regular props in React 19

    line 327
  7. Very specific:

    Use react-helmet — native metadata support built in

    line 328
  8. Distinctive:

    Create promises inside component render

    line 329
  9. Very specific:

    Add useEffectEvent functions to dependency arrays

    line 332
  10. Distinctive:

    Add global state for state that only 1-2 components need

    line 334
  11. Very specific:

    Use useOptimistic for mutations that should feel instant

    line 339
  12. Distinctive:

    Default to native React — add a dependency only when you hit a real limitation

    line 341

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill 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
SKILL.md

React 19+ Guidelines

React 19.2, TypeScript, client-side patterns. No overlap with the Next.js skill.

Reference Files

Load these when the topic comes up — don't load all of them upfront:

  • references/routing.md — React Router v7 and TanStack Router
  • references/state-management.md — state decision table, Zustand, TanStack Query, RHF
  • references/architecture.md — project structure, component design, performance

New Hooks at a Glance

HookReplaces / Solves
useActionStateManual useState + useEffect for async operations
useOptimisticManual optimistic state rollback logic
useFormStatusProp-drilling isPending into submit buttons
use(promise)useEffect + useState for data fetching
use(Context)useContext (but works conditionally)
useEffectEventStale closure bugs in useEffect dependencies

useActionState

Manages async action state — pending, result, error — in one hook:

import { useActionState } from 'react'

async function updateUsername(prevState: State, formData: FormData) {
  const username = formData.get('username') as string
  const res = await fetch('/api/user', {
    method: 'POST',
    body: JSON.stringify({ username }),
  })
  if (!res.ok) return { error: 'Failed to update' }
  return { success: true, username }
}

type State = { error?: string; success?: boolean; username?: string } | null

function UsernameForm() {
  const [state, action, isPending] = useActionState(updateUsername, null)

  return (
    <form action={action}>
      <input name="username" />
      <button disabled={isPending}>{isPending ? 'Saving...' : 'Save'}</button>
      {state?.error && <p>{state.error}</p>}
      {state?.success && <p>Updated to {state.username}</p>}
    </form>
  )
}

useOptimistic

Show the expected result immediately, roll back automatically if the action fails:

import { useOptimistic, useActionState } from 'react'

type Message = { id: string; text: string; pending?: boolean }

function MessageThread({ messages }: { messages: Message[] }) {
  const [optimisticMessages, addOptimistic] = useOptimistic(
    messages,
    (state, newText: string) => [
      ...state,
      { id: crypto.randomUUID(), text: newText, pending: true },
    ]
  )

  const [, sendAction, isPending] = useActionState(
    async (_: null, formData: FormData) => {
      const text = formData.get('text') as string
      addOptimistic(text)
      await sendMessage(text)
      return null
    },
    null
  )

  return (
    <>
      <ul>
        {optimisticMessages.map(m => (
          <li key={m.id} style={{ opacity: m.pending ? 0.5 : 1 }}>{m.text}</li>
        ))}
      </ul>
      <form action={sendAction}>
        <input name="text" />
        <button disabled={isPending}>Send</button>
      </form>
    </>
  )
}

useFormStatus

Access the parent form's pending state from inside a child — no prop drilling:

import { useFormStatus } from 'react-dom'

// Must be rendered INSIDE a <form>
function SubmitButton({ label }: { label: string }) {
  const { pending } = useFormStatus()
  return (
    <button type="submit" disabled={pending}>
      {pending ? 'Saving...' : label}
    </button>
  )
}

use()

Read promises and context in render — works conditionally, unlike hooks:

import { use, Suspense } from 'react'

// Read a promise — component suspends until resolved
function UserCard({ userPromise }: { userPromise: Promise<User> }) {
  const user = use(userPromise)
  return <div>{user.name}</div>
}

// Wrap in Suspense — required
function Page() {
  const userPromise = fetchUser(userId)  // create promise OUTSIDE render
  return (
    <Suspense fallback={<Skeleton />}>
      <UserCard userPromise={userPromise} />
    </Suspense>
  )
}

// Read context conditionally (unlike useContext)
function ThemedButton({ show }: { show: boolean }) {
  if (!show) return null
  const theme = use(ThemeContext)  // after early return — fine
  return <button style={{ background: theme.primary }}>Click</button>
}

Never create promises inside render — creates a new promise on every render:

// Never do this
function Bad() { const data = use(fetch('/api').then(r => r.json())) }

// Create outside, pass as prop or via cache()
const promise = fetch('/api').then(r => r.json())
function Good() { const data = use(promise) }

useEffectEvent

Extract non-reactive logic from Effects without stale closure bugs:

import { useEffect, useEffectEvent } from 'react'

function ChatRoom({ roomId, theme }: { roomId: string; theme: string }) {
  const onConnected = useEffectEvent(() => {
    showNotification('Connected!', theme)  // always reads latest theme
  })

  useEffect(() => {
    const connection = connect(roomId)
    connection.on('connected', onConnected)  // NOT in dependency array
    return () => connection.disconnect()
  }, [roomId])  // only reconnects when roomId changes
}
  • Never add useEffectEvent functions to the dependency array
  • Only call them from inside Effects

Refs

Refs are a regular prop in React 19 — no more forwardRef:

// ref as a prop directly
function Input({ ref, ...props }: React.ComponentProps<'input'>) {
  return <input ref={ref} {...props} />
}

// Cleanup functions in refs
<input
  ref={(node) => {
    doSomething(node)
    return () => cleanup(node)  // called on unmount
  }}
/>

Document Metadata

Render <title>, <meta>, <link> directly in components — no react-helmet:

function ProductPage({ product }: { product: Product }) {
  return (
    <>
      <title>{product.name} | My Store</title>
      <meta name="description" content={product.description} />
      <main><h1>{product.name}</h1></main>
    </>
  )
}

React hoists to <head> automatically, deduplicates, and handles SSR correctly.


useTransition

Wrap non-urgent state updates to keep the UI responsive:

const [isPending, startTransition] = useTransition()

function handleChange(value: string) {
  setQuery(value)                        // urgent — updates immediately
  startTransition(async () => {
    const data = await searchAPI(value)  // non-urgent — can be interrupted
    setResults(data)
  })
}

React Compiler

Automatically memoizes components — useMemo, useCallback, memo largely unnecessary:

// Before compiler — manual memoization
const value = useMemo(() => compute(a, b), [a, b])
const cb = useCallback(() => doThing(id), [id])

// With compiler — write normal code, compiler handles it
const value = compute(a, b)
function handleClick() { doThing(id) }

Don't remove existing useMemo/useCallback proactively — only when compiler is confirmed enabled.


Context

// React 19 — no .Provider needed
<ThemeContext value="dark">
  <Page />
</ThemeContext>

// use() works conditionally, useContext doesn't
function Component({ show }: { show: boolean }) {
  if (!show) return null
  const theme = use(ThemeContext)  // after early return — fine
  return <div data-theme={theme} />
}

Suspense & Error Boundaries

import { Suspense } from 'react'
import { ErrorBoundary } from 'react-error-boundary'

function Dashboard() {
  return (
    <ErrorBoundary fallback={<ErrorMessage />}>
      <Suspense fallback={<DashboardSkeleton />}>
        <DashboardContent />
      </Suspense>
    </ErrorBoundary>
  )
}

Anti-Patterns

Never:

  • Use forwardRef — refs are regular props in React 19
  • Use react-helmet — native metadata support built in
  • Create promises inside component render
  • Disable lint rules to fix stale closures — use useEffectEvent
  • Manually manage loading/error state for forms — use useActionState
  • Add useEffectEvent functions to dependency arrays
  • Reach for a library before trying the native React solution
  • Add global state for state that only 1-2 components need

Always:

  • TypeScript throughout
  • Wrap async reads with <Suspense> when using use(promise)
  • Use useOptimistic for mutations that should feel instant
  • Let the React Compiler handle memoization
  • Default to native React — add a dependency only when you hit a real limitation

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.