Irbisa · Cheatsheet
React Fundamentals
JSX, components, props, children and composition, conditional rendering, lists and keys, one-way data flow, React 19 basics
What is React, and what does it mean that React is declarative?
What is the virtual DOM, and does it make React faster than the real DOM?
What is JSX, and what does it compile to?
import { jsxs as _jsxs } from 'react/jsx-runtime'; const name = 'Ada'; // What you writeconst written = <h1 className="title">Hello, {name}</h1>;…What is a React component, and why must its name start with a capital letter?
interface AvatarProps { name: string; url: string;} function Avatar({ name, url }: AvatarProps) {…What is the difference between class and function components, and is there anything you still need a class for?
import { Component, useState } from 'react'; // class: one state object that setState merges into; handlers need `this`export class ClassCounter extends Component<{ step: number }, { count: number }> { state = { count: 0 };…What are props, and why can a component not change its own props?
What is the difference between props and state?
What is the
childrenprop, and why does React prefer composition over inheritance?import type { ReactNode } from 'react'; interface CardProps { title: string; footer?: ReactNode; children: ReactNode;…What are the ways to render something conditionally in JSX?
interface InboxProps { loading: boolean; error?: string; unread: number; isAdmin: boolean;}…How do you render a list in React, and why does each item need a
key?interface Todo { id: string; title: string; done: boolean;}…What is a Fragment, and when do you need one?
import { Fragment } from 'react'; interface Term { id: string; word: string; meaning: string;…How do you start a new React project in 2026, and why is
create-react-appdeprecated?What does this component render when the cart is empty, and how do you fix it?
interface CartProps { items: string[];} export function Cart({ items }: CartProps) { return ( <div> <h2>Cart</h2> {items.length && <p>{items.length} items in your cart</p>} </div> );}Find the bug: after the first row is deleted, the note typed in it shows up in the next row.
import { useState } from 'react'; function Row({ title }: { title: string }) { const [note, setNote] = useState(''); return ( <li> {title} <input value={note} onChange={(e) => setNote(e.target.value)} /> </li> );} export function List({ items }: { items: { id: string; title: string }[] }) { return <ul>{items.map((item, index) => <Row key={index} title={item.title} />)}</ul>;}What does one-way data flow mean in React, and how does a child send data back to its parent?
import { useState } from 'react'; interface FilterProps { value: string; onChange: (value: string) => void;}…Why must a React component be pure, and what counts as a side effect during render?
let renderCount = 0; // wrong: mutates a module variable during renderexport function CupBad({ guest }: { guest: number }) { renderCount++; return <h2>Tea cup #{renderCount} for guest {guest}</h2>;…Find the bug: the search input loses focus after every keystroke.
import { useState } from 'react'; export function SearchPage() { const [query, setQuery] = useState(''); function SearchBox() { return <input value={query} onChange={(e) => setQuery(e.target.value)} />; } return ( <main> <SearchBox /> <p>Results for {query}</p> </main> );}What breaks when a component is called as a function,
{Row({ item })}, instead of rendered as<Row item={item} />?import { useState } from 'react'; type Item = { id: string; title: string; details: string }; function Row({ item }: { item: Item }) { const [open, setOpen] = useState(false); return ( <li onClick={() => setOpen(!open)}> {item.title} {open && item.details} </li> );} export function List({ items }: { items: Item[] }) { return <ul>{items.map((item) => Row({ item }))}</ul>;}Which class lifecycle methods map to which hooks, and which ones have no direct hook equivalent?
import { Component, useEffect } from 'react'; // before: three lifecycle methods keep one connection in syncexport class ChatRoomClass extends Component<{ roomId: string }> { connection = createConnection(this.props.roomId);…What changed in React 19 that you notice in everyday component code?
import type { ComponentProps } from 'react'; // React 19: ref arrives as a normal prop, no forwardRef wrapperfunction TextInput({ ref, ...props }: ComponentProps<'input'>) { return <input ref={ref} className="input" {...props} />;}…When does React keep a component's state and when does it reset it, and how do you use
keyto force a reset?import { useState } from 'react'; function ChatInput({ contact }: { contact: string }) { const [draft, setDraft] = useState(''); return ( <textarea…