Scheda di riferimento React
Un riferimento React 19 stampabile e ricercabile — componenti, JSX, hook, le nuove API Actions, context, ref e prestazioni. Gratis.
Components & JSX
12function App() { return <h1>Hi</h1>; }
export default function App() {}
<Greeting name="Ada" />
{1 + 2} or {user.name}
<>{a}{b}</>
<div className="card">
{isOpen && <Menu />}
{ok ? <Yes /> : <No />}
{items.map(i => <li key={i.id}>{i.t}</li>)}
function Btn({ label, onClick }) {}
function Card({ children }) { return children; }
<input value={v} onChange={onChange} />
Rendering & setup
10import { createRoot } from 'react-dom/client'
createRoot(document.getElementById('root')).render(<App/>)
import { StrictMode } from 'react'
<StrictMode><App /></StrictMode>
import { hydrateRoot } from 'react-dom/client'
hydrateRoot(el, <App />)
root.unmount()
import App from './App.jsx'
<App {...props} />
export { Button, Card }
State & effects
12const [count, setCount] = useState(0)
setCount(c => c + 1)
setUser(u => ({ ...u, name }))
useEffect(() => { run(); }, [dep])
useEffect(() => { /* once */ }, [])
useEffect(() => () => cleanup(), [])
const ref = useRef(null)
const [state, dispatch] = useReducer(r, init)
const theme = useContext(ThemeContext)
const memo = useMemo(() => calc(a), [a])
useLayoutEffect(() => {}, [])
useSyncExternalStore(sub, get)
React 19 hooks & APIs
12import { use } from 'react'
const data = use(promise)
const theme = use(ThemeContext)
const [state, action, pending] = useActionState(fn, init)
const [opt, addOpt] = useOptimistic(state, reducer)
const { pending } = useFormStatus()
const [isPending, startTransition] = useTransition()
startTransition(async () => await save())
const deferred = useDeferredValue(value)
const id = useId()
<title>Page title</title>
function Input({ ref }) {}
Forms & Actions
12<form action={handleSubmit}>
function handleSubmit(formData) {}
formData.get('email')
const [state, action] = useActionState(submit, null)
<form action={action}>
const [s, a, pending] = useActionState(fn, init)
return { error: 'Invalid' }
function Submit() { const { pending } = useFormStatus() }
<button disabled={pending}>Save</button>
import { requestFormReset } from 'react-dom'
requestFormReset(formEl)
<form action={action}><Submit /></form>
Props & composition
10function Hi({ name = 'Guest' }) {}
function Box({ children }) { return children; }
<Box><p>Inside</p></Box>
function List({ render }) { return render(); }
<List render={() => <Item />} />
<Input {...props} />
const { id, ...rest } = props
<Avatar {...rest} size="lg" />
function Btn(props: BtnProps) {}
<Slot label={<b>Hi</b>} />
Events
10<button onClick={handleClick}>
function handleClick(e) {}
<input onChange={e => set(e.target.value)} />
<form onSubmit={e => e.preventDefault()}>
e.stopPropagation()
<li onClick={() => remove(id)}>
<input onKeyDown={e => e.key === 'Enter'}
<div onMouseEnter={hover}>
e.currentTarget.value
<button onClick={() => {}} type="button">
Lists & keys
10arr.map(x => <li key={x.id}>{x.t}</li>)
key={item.id}
key={index}
users.map(u => <Card key={u.id} {...u} />)
{list.length === 0 && <Empty />}
import { Fragment } from 'react'
<Fragment key={id}>{a}{b}</Fragment>
{rows.filter(r => r.on).map(...)}
Keys must be unique among siblings
{[...Array(n)].map((_, i) => ...)}
Context
10const ThemeContext = createContext('light')
import { createContext } from 'react'
<ThemeContext value={theme}>
<ThemeContext value={theme}><App /></ThemeContext>
const theme = useContext(ThemeContext)
const theme = use(ThemeContext)
if (cond) { const t = use(Ctx); }
export const ThemeContext = createContext()
<Ctx value={{ user, setUser }}>
Avoid new objects each render
Refs
10const inputRef = useRef(null)
<input ref={inputRef} />
inputRef.current.focus()
function Field({ ref }) { return <input ref={ref} /> }
<Field ref={inputRef} />
useImperativeHandle(ref, () => ({ focus }))
const setRef = node => { box = node; }
<div ref={setRef} />
const count = useRef(0)
ref={node => { return () => cleanup(); }}
Performance
10const Memo = memo(Component)
import { memo } from 'react'
const value = useMemo(() => calc(a), [a])
const fn = useCallback(() => f(a), [a])
const Lazy = lazy(() => import('./Big.jsx'))
import { lazy, Suspense } from 'react'
<Suspense fallback={<Spin />}><Lazy /></Suspense>
startTransition(() => setQuery(q))
const slow = useDeferredValue(query)
React Compiler auto-memoizes
Misc & metadata
10<Suspense fallback={<Loading />}>
class ErrorBoundary extends Component {}
<title>My Page</title>
<meta name="description" content="..." />
<link rel="stylesheet" href="..." />
<Comp key={id} />
React.lazy(() => import('./Page.jsx'))
createPortal(node, container)
{/* a comment */}
cleanup return in useEffect
Nessuna voce corrisponde a “:q”.
Informazioni su Scheda di riferimento React
Questo cheat sheet di React è dedicato a React 19 e mappa la libreria per concetti: componenti e JSX, rendering e configurazione, stato ed effetti, gli hook e le API di React 19, form e Actions, props e composizione, eventi, liste e chiavi, context, ref, performance, e metadati più varie.
Copre sia le basi che usi in ogni componente — useState, useEffect, props, chiavi, input controllati — sia le nuove aggiunte di React 19, inclusi i pattern dei form basati su Actions, così funziona sia come ripasso sia come ponte verso le API attuali.
La scheda è gratuita e client-side. Filtra hook e pattern in tempo reale con il campo di ricerca, salta tra le sezioni dall'indice fisso, copia qualsiasi snippet con un clic e stampa la pagina come riferimento mentre costruisci i componenti.
Come usare Scheda di riferimento React
- Scorri le sezioni, da Componenti e JSX e Stato ed effetti fino a Hook e API di React 19 e Performance.
- Cerca un hook o un concetto come useEffect, key o context per filtrare la scheda in tempo reale.
- Vai a Form e Actions o Ref tramite la barra laterale fissa quando ti serve un pattern specifico.
- Clicca su uno snippet o sulla sua icona di copia per copiare il codice nel tuo componente.
- Stampa la scheda come riferimento React offline.