function App() {
return <h1>Hello</h1>;
} Function component
const App = () => <h1>Hello</h1>;
Arrow function component
function Greet({ name }) {
return <p>Hi {name}</p>;
} Component with props
export default App;
Export component as default
<App title="Hi" count={5} /> Use component with props
<> <A /> <B /> </>
Fragment (no wrapper)
{items.map(item => <li key={item.id}>{item.name}</li>)} Render list with keys
{condition && <Alert />} Conditional render (and)
{loading ? <Spinner /> : <Data />} Conditional render (ternary)
<div className="btn primary">Click</div>
CSS class (className)
<div style={{color: 'red', fontSize: 14}}>X</div> Inline styles (object)
<button onClick={() => setN(n + 1)}>+</button> Event handler
const [count, setCount] = useState(0);
State with initial value
setCount(count + 1);
Update state
setCount(c => c + 1);
Functional state update
setUser({...user, name: 'Alice'}); Update object state (spread)
setItems([...items, newItem]);
Append to array state
useEffect(() => {
fetchData();
}, []); Run once on mount
useEffect(() => {
...
}, [dep1, dep2]); Run when deps change
useEffect(() => {
const id = setInterval(...);
return () => clearInterval(id);
}, []); Effect with cleanup
const ref = useRef(null);
<input ref={ref} /> DOM ref
const renders = useRef(0);
Mutable ref (no re-render)
const value = useMemo(() => expensive(x), [x]);
Memoize computation
const fn = useCallback(() => doThing(x), [x]);
Memoize callback
const theme = useContext(ThemeContext);
Consume context
const [state, dispatch] = useReducer(reducer, initial);
Reducer pattern
function useDebounce(value, delay) { ... } Custom hook
const [email, setEmail] = useState('');
<input value={email} onChange={e => setEmail(e.target.value)} /> Controlled input
<input type="checkbox" checked={on} onChange={e => setOn(e.target.checked)} /> Controlled checkbox
<form onSubmit={e => { e.preventDefault(); submit(); }}> Submit handler
<input ref={inputRef} defaultValue="hi" /> Uncontrolled input (ref)
const ThemeContext = createContext('light'); Create context
<ThemeContext.Provider value="dark"> <App /> </ThemeContext.Provider>
Provide context value
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
</Routes>
</BrowserRouter> Basic routes
<Link to="/about">About</Link>
Navigation link
const navigate = useNavigate();
navigate('/home'); Programmatic navigation
const { id } = useParams(); Read URL params
const [params] = useSearchParams();
Read query string
const Button = React.memo(({ onClick }) => ...); Memoize component
const Heavy = lazy(() => import('./Heavy'));
<Suspense fallback={<Loader/>}><Heavy /></Suspense> Code splitting with Suspense
React Cheat Sheet — Hooks, Components, JSX & Context API Reference
React arrived in 2013 with a JSX view layer and a class-component model; the function-plus-hooks model that landed in 2019 has been the recommended approach since, and most React code today is closer to a list of pure render functions than to the original class lifecycle. The cheatsheet below covers 40+ patterns across components, hooks, forms, context, routing, and performance. Most trouble in real components doesn't come from forgetting JSX syntax. It comes from quirks that look ordinary but bite. A `useEffect` reading a state value without listing it in the dependency array reads the value from the render that created the effect, not the latest one. A list rendered without a stable `key` reuses DOM nodes in surprising orders during reorders. The snippets below are the ones an author reaches for when debugging exactly that — the dependency array that ends an effect loop, the functional updater that survives batching, the cleanup that stops a leaking interval — without rereading the React reference from line one each time.
Common pitfalls in React
A few patterns earn their place on the first screen of any React component. The functional state updater `setCount(c => c + 1)` should replace the value-form whenever the new state depends on the previous one — it survives batching and avoids the classic off-by-N counter bug. Effect dependency arrays should list every reactive value the effect reads, including props, state, and locally declared functions; the ESLint `react-hooks/exhaustive-deps` rule is worth keeping on, because the cases it catches are almost always real stale-closure bugs. Lists need a stable `key` from the data itself, not the array index — indexes shift on reorder and confuse the reconciler. Cleanup functions returned from `useEffect` matter for intervals, subscriptions, and event listeners, not just for unmount but for every re-run of the effect when its dependencies change. The cheatsheet groups all of this into Components, Hooks, Forms, Context, Routing, and Performance so the right section is one click away.
- 40+ React patterns with JSX
- Full hooks coverage (useState, useEffect, useRef, etc.)
- Controlled forms and submit handlers
- Context API and providers
- React Router v6 routing
- React.memo and lazy loading
Free. No signup. Your inputs stay in your browser. Ads via Google AdSense (consent required).
By Marco B. ·