Glossary term
React
React builds user interfaces from components that turn data and state into what users see. It is a library rather than a complete application framework, and it does not dictate the backend, database, or overall deployment model.
In brief
A library for component-based user interfaces.
JavaScript is a programming language; React is a library built on top of it. Developers describe a screen as a set of components, and React calls those components with their current inputs to determine what to display. JSX lets markup-like syntax live next to rendering logic; it is neither an HTML string nor a separate new language.
The DOM is not part of the core React package. A web application uses React DOM to create its root, commit the necessary DOM operations when something changes, and attach interactivity to server-generated HTML during hydration. Other renderers let React target platforms beyond the web.
React does not provide a complete router, database layer, or backend. Next.js, by contrast, is a React framework that adds routing, server capabilities, a build system, and application-wide conventions. React is not synonymous with a SPA either: it can power one interactive part of a page or an application that combines server and client rendering.
What problem it solves
Keeps the interface in sync with data and state.
With direct DOM manipulation, application code must track which element to create, update, or remove after every interaction. React lets developers declare the desired result for the current props and state, then organise recurring behaviour into reusable components.
- product cards, filters, shopping carts, forms, and other interfaces that respond to user events
- reusing visual patterns and behaviour through components instead of duplicating DOM operations
- modelling loading, error, empty, and success states while communicating with an API
- assembling larger screens from smaller pieces with clear inputs and responsibilities
- adding interactivity incrementally to server-generated HTML or building a larger frontend
Practical example
A product card with availability and cart actions
The name, price, availability, and cart handler arrive as props. Local state records only how many additions were made from this card. The function passed to onClick runs only when the event occurs; rendering itself does not modify surrounding data or the DOM.
In a real application, onAddToCart would usually call a higher application layer. That layer needs to expose progress and errors, handle repeated submissions, and respect the authoritative server response. A number stored locally in the component is not the source of truth for an order.
TypeScript / React (TSX)
import { useState } from 'react';
type ProductCardProps = {
id: string;
name: string;
price: string;
inStock: boolean;
onAddToCart: (productId: string) => Promise<void>;
};
export function ProductCard({
id, name, price, inStock, onAddToCart,
}: ProductCardProps) {
const [addedCount, setAddedCount] = useState(0);
const [isAdding, setIsAdding] = useState(false);
const [error, setError] = useState<string | null>(null);
async function handleAdd() {
setIsAdding(true);
setError(null);
try {
await onAddToCart(id);
setAddedCount((count) => count + 1);
} catch {
setError('Could not add the item. Please try again.');
} finally {
setIsAdding(false);
}
}
return (
<article>
<h2>{name}</h2>
<p>{price}</p>
<p>{inStock ? 'In stock' : 'Out of stock'}</p>
<button type="button" disabled={!inStock || isAdding} onClick={handleAdd}>
{isAdding ? 'Adding…' : 'Add to cart'}
</button>
{addedCount > 0 && <p aria-live="polite">Added: {addedCount}×</p>}
{error && <p role="alert">{error}</p>}
</article>
);
}
How it works
Props and state → component render → React DOM → user interface.
Rendering in React does not mean that every DOM node changes. React first computes a new description of the interface, then applies only the necessary changes during the commit phase.
- Props provide input A parent passes values and callbacks to its child. Props are a read-only snapshot for a particular render and must not be mutated by the component.
- State provides memory Hooks such as useState or useReducer preserve values between renders. Updating state queues another render; it does not immediately alter the snapshot already in progress.
- React calls components Function components calculate JSX from props, state, and context as pure functions. The same inputs should produce the same result, without side effects during rendering.
- React DOM commits changes The web renderer updates only the DOM properties and nodes that differ in the new result. The browser then paints the screen.
- An event triggers the next update A click, form change, or response from an external system may update state and start the cycle again.
Core concepts
Components separate responsibilities; Hooks expose React features.
Function components are the standard style in modern React. Class components remain supported for existing applications, but the official documentation does not recommend them for new code.
Components and JSX
A component is a JavaScript function that returns React nodes. JSX makes elements and expressions easier to write; the resulting semantics and accessibility still depend on the HTML you choose.
Props and state
Props come from a parent, while state belongs to a particular component position in the tree. A value that can be derived from existing props or state usually does not need to be stored a second time.
Hooks
Hooks such as useState, useContext, and useRef make React features available inside components. They are not an alternative to components, and the Rules of Hooks require them to be called at the top level of a React function.
Events and forms
An event handler is passed as a function, not as the result of calling it immediately. A form may be controlled with state, but native labels, validation, submission, and focus behaviour still matter.
Composition and context
Components compose through nesting and children. Context exposes a value to distant descendants, but it should not replace ordinary props without reason or turn every value into global state.
Refs and Effects
A ref provides targeted access to a DOM node or a value outside rendering. An Effect synchronises a component with an external system; both are escape hatches, not the default home for ordinary data flow.
Benefits, limitations, and common mistakes
Declarative UI helps, but poorly modelled state remains complex.
Practical benefits
- reusable components with explicit inputs and composition
- a consistent event → state update → render model
- sharing behaviour through custom Hooks without duplicating UI
- support for client, server, and static rendering through the chosen framework
Limitations and common mistakes
- using useEffect for a derived value or a direct response to a click instead of computing it or using an event handler
- moving everything into global state and obscuring data ownership
- treating local React state as remote server state that may become stale
- splitting components solely by line count rather than cohesive responsibility
- assuming every re-render is a problem without measuring actual performance
- treating React as an automatic guarantee of accessibility, safe HTML, or correct focus management
When to use it and how it compares
React suits stateful interfaces, but not every page needs it.
In an e-commerce administration tool, React can bring together filters, variant editing, live validation, and the status of several API requests. A small content page with links and one form may be simpler as server-rendered HTML with targeted JavaScript. The right choice depends on the amount of interaction, the lifespan of the project, and the team’s ability to maintain the frontend—not on the popularity of the library.
With pure client-side rendering, JavaScript creates the primary content in the browser. React can also hydrate server-generated HTML, and a framework can prerender components. React is therefore not synonymous with CSR, SSR, or any particular navigation model.
The API remains a separate contract. React can display its data and the local request state, but the backend still validates input, makes authorisation decisions, and confirms changes to the cart or order. A server-state library or framework may handle caching and fetching better than a hand-written useEffect in every component.
A React component is not a Web Component. React evaluates a React component and its props belong to the React tree; a Web Component is a standard custom element registered with the browser. The two models can interoperate, but they differ in lifecycle, distribution, and DOM access.
Implementation checklist
Establish state ownership before optimising.
A good component has a clear purpose, semantic output, and predictable data flow. Both performance and accessibility need to be tested along real user journeys.
- keep state as close as possible to the components that genuinely share it, and do not duplicate derived values
- perform user-initiated actions in event handlers and reserve Effects for synchronisation with external systems
- model loading, error, empty, and success states without presenting a local optimistic update as server confirmation
- use semantic HTML, visible focus indicators, form labels, and keyboard controls
- profile the specific issue before adding memoisation, and monitor the amount of client-side JavaScript
Frequently asked questions
React without the common misconceptions
Is React a framework?
Not in the usual sense. React is a user-interface library. A framework such as Next.js adds routing, server features, a build system, and broader application conventions.
Is React only for single-page applications?
No. It can power one part of a traditional page, an entire SPA, or an interface that combines server, static, and client rendering.
Do Hooks replace components?
No. Hooks expose state, context, refs, and other capabilities to function components and custom Hooks. They do not render an interface on their own.
Does every piece of logic belong in useEffect?
No. Derived values are usually calculated while rendering, and user actions belong in event handlers. Effects are mainly for synchronising with external systems.
Does React guarantee performance and accessibility?
No. The outcome depends on data flow, the amount of client-side code, semantic HTML, focus management, and measurements of how the application actually behaves.
Hands-on experience
I assess frontend interfaces together with their APIs and server boundaries.
When building web applications, I align interface state, failure scenarios, and accessibility with the authoritative behaviour of the backend.