React Best Practices: 10 Habits That Keep Apps Maintainable
React best practices are simple habits: small components, state close to where it is used, clean hooks, and tests for the parts that break most.
On this page
Short answer
React best practices are the habits that keep a React app easy to change as it grows: small components with one job, state kept close to where it is used, hooks that do one thing, and rendering kept cheap. Each one prevents a specific pain, such as a component that cannot be reused or a page that slows down as its list grows.
What are React best practices?
React best practices are the working habits that keep a React codebase readable, testable and fast as it grows. React itself is a library for building user interfaces from components, and it leaves most decisions about structure, state and data to the team. That freedom is the reason habits matter: two teams can build the same feature and end up with very different code.
The practices fall into four groups: how components are shaped, where state lives, how side effects are handled, and how rendering stays fast. A team that agrees on these four early spends less time arguing in code review and less time untangling a component that grew too big.
None of these practices needs a new tool. They are choices about where code goes and how big a piece of it is allowed to get, and they pay off most in the second year of a project, when the first team has moved on and a new developer has to change the code.
How should you structure components?
Components should be small and do one job. A component that renders a list, fetches data, formats dates and handles a form is four components wearing one name, and every change to it risks breaking the other three. Split by job, and the parts become easy to test and easy to reuse.
| Practice | What it means | What it prevents |
|---|---|---|
| One job per component | Each component renders or handles one thing | Giant components nobody wants to touch |
| Small props | Pass only the data the component needs | Props that change for unrelated reasons |
| Composition over props | Pass children in instead of many flags | Prop lists that grow with every feature |
| Separate logic from UI | Keep data fetching and rules in hooks | UI code mixed with business rules |
| Consistent file layout | Same folder and naming pattern everywhere | Time lost finding where code lives |
| Name by purpose | Names say what it does, not how it looks | Names that lie after the next redesign |
Composition deserves a word of its own. Instead of a component with ten boolean props for every variation, pass the varying parts in as children. The component stays small, the caller decides what goes inside, and the next variation needs no change to the component at all.
How do you manage state well?
State should live as close as possible to where it is used. A form field's value belongs in the form component, not in a global store, because no other part of the app needs it. State that climbs higher than it must becomes a shared dependency, and every change to it ripples through components that never asked for it.
Use local state first, lift it only when two components genuinely share it, and reach for a global store only when state is needed across distant parts of the app, such as the signed-in user or the shopping cart. Most apps need far less global state than their developers expect.
Keep derived values out of state. If a total can be calculated from a list, calculate it when rendering instead of storing it, because a stored total can fall out of sync with the list it came from. The same applies to filtered lists and formatted strings: compute them, do not store them.
For a plain introduction to the library itself, see what React is and how it works.
How do hooks stay clean?
Hooks should do one thing and say so in their name. A hook called useUserData that fetches the user, formats the name, checks permissions and logs an event is doing four jobs, and it cannot be tested or reused without all four. Split it, and each piece becomes simple.
Keep effects honest. An effect should describe what it synchronises with the outside world, such as a subscription or a title update, and clean up after itself. An effect that runs on every render, or that depends on values it never lists, is a bug waiting for the right moment.
Do not copy props into state. A component that stores a prop in state and then reads the state will show stale data when the prop changes, and the fix is usually to read the prop directly. If a value needs adjusting, derive it during rendering instead.
How do you keep rendering fast?
Rendering stays fast when components render only when their own data changes. The most common waste is a list where every row re-renders because the parent re-rendered, even though only one row changed. Memoising the row component and giving each row a stable key fixes most of it.
Keys matter more than they look. A key should identify the item, such as its id, not its position in the list. An index key makes React reuse the wrong row when the list is sorted or filtered, which shows up as a checkbox that moves to the wrong item or an input that keeps the wrong text.
Split large pages with lazy loading so the user downloads only the code for the screen they are on. A dashboard that loads every chart library on the first screen is slow for everyone, while a page that loads each chart when it is opened stays fast.
Example (hypothetical): a 200-row list that lags on every keystroke
Example (hypothetical): a search page renders 200 rows, and each row takes about 5 milliseconds to render. On every keystroke the whole list re-renders, so 200 rows times 5 milliseconds is 1,000 milliseconds, a full second of lag before the typed character appears.
The team memoises the row component and adds virtualisation, so only the 20 visible rows render. That is 20 rows times 5 milliseconds, or 100 milliseconds per keystroke, ten times faster. The search input also gets a short delay so it only filters after the user pauses typing, which cuts the number of renders further.
The fix took less than a day, and the page went from unusable to smooth. The lesson is that rendering problems are usually a list problem, not a React problem, and the fix is to render less, not to render faster.
What are the common mistakes?
The most common mistakes are storing everything in global state, copying props into state, using index keys in lists, and letting components grow until nobody can change them safely.
- Global state for everything. Form values and toggles in a global store create dependencies across the whole app.
- Copying props into state. The copy goes stale when the prop changes, and the component shows old data.
- Index keys in lists. Sorting or filtering then reuses the wrong row, and inputs keep the wrong text.
- Effects that do too much. An effect that fetches, formats and logs is four jobs hiding in one.
- No tests for the tricky parts. Date logic, price maths and permission checks break quietly without tests.
Tests deserve a final note. A team does not need tests for every component, but the parts that break most, such as date maths, price calculations and permission checks, should have them. A test that catches a regression in a price calculation pays for itself the first time it runs.
Key takeaways
- Keep components small, with one job each, and split them before they grow
- State lives close to where it is used; global state is for shared data only
- Derived values are calculated during rendering, never stored in state
- Hooks do one thing, effects clean up after themselves, and props are never copied into state
- Lists render fast when rows are memoised, keyed by id, and only visible rows render
Frequently asked questions
What is React?
React is a JavaScript library for building user interfaces from components, which are small pieces of a page that manage their own markup and behaviour. It is maintained by Meta and is widely used for web apps, dashboards and single-page applications.
When should state go in a global store?
Only when distant parts of the app genuinely need the same data, such as the signed-in user or a shopping cart. Local state first, lifted state when two components share it, and a global store only for data that crosses the whole app.
Why should I not use the list index as a key?
React uses the key to match rows between renders. An index key makes React reuse the wrong row when the list is sorted or filtered, so a checkbox or input can end up attached to the wrong item.
What is the difference between state and props?
Props are data a parent passes into a component, and the component cannot change them. State is data the component owns and can change, such as a form value or a toggle. Copying a prop into state is a common source of stale data.
How do I know if my React app is too slow?
Watch for typing lag, slow list scrolling and pages that feel heavy on first load. The usual causes are lists that re-render every row, large bundles loaded up front, and effects that run more often than they should.
Do React best practices change with each release?
The core habits, small components, local state and clean hooks, have stayed stable for years. New features change the tools, such as how data is fetched, but they do not change the habit of keeping each piece small and honest.