How Do You Build a Counter App in React Step by Step?
Build a React counter app from an empty Vite project, adding buttons, handlers, a step size and limits one step at a time.
47 posts about React: questions with answers, tutorials and articles, newest first.
Build a React counter app from an empty Vite project, adding buttons, handlers, a step size and limits one step at a time.
Learn the useState hook syntax, lazy initial state, the rules of hooks and the mistakes beginners make when updating state.
State is the data a component remembers between renders. Learn why plain variables are not enough and how state differs from props.
Derive the visible list from search and sort state with filter() and a sorted copy, then render it with map() and stable keys.
The React key prop lets React match list items between renders. Learn what goes wrong with index keys and how to choose stable, unique keys.
Call map() on an array and return keyed JSX to render a list in React. See component rows, filtering, empty states and common errors.
Use the ternary for two outcomes and && to show or hide one element in JSX. Includes the stray 0 trap and tips for avoiding nested ternaries.
Use if, the ternary, && or null to render components conditionally in React. Includes the zero pitfall and a guide to choosing a technique.
Wrap the handler in an arrow function to pass arguments in React. Learn the event object, data attributes and when inline functions matter.
Call event.preventDefault() in your onSubmit handler to stop the page reload. See controlled and FormData examples and the mistakes to avoid.
Handle React onChange on an input by storing the value in state and updating it from event.target.value. Covers checkboxes, selects and multi-field forms.
Use the React onClick handler by passing a function, not a call. See state updates, arguments, preventDefault, stopPropagation and accessible buttons.
Props are read-only in React to keep components pure and data flow one-way. See what to avoid, how to copy safely and where changing values should live.
Props drilling means forwarding props through layers that never use them. See when it matters and fix it with composition, Context or a state library.
Pass a function as a prop in React so a child can notify its parent. See callbacks, arguments, TypeScript types and the parentheses mistake.
Destructure props in React to replace props.name with name. See parameter and body syntax, defaults, renaming, rest props and common mistakes.
Set default prop values in React with default parameters in the destructured props. See when they apply, the null trap and how to replace defaultProps for React 19.
Pass props to a React component as JSX attributes and read them by destructuring. Covers functions, objects, children, spread syntax and why props are read-only.
Function components use Hooks and plain functions, class components use this and lifecycle methods. See a side by side comparison and which one to choose today.
Use dangerouslySetInnerHTML with an __html object to render HTML strings in React. Learn why it is risky, how to sanitise input and what to use instead.