Skip to main content

React Component Design Patterns Every Developer Should Know

A friendly guide to react component design, from state and effects to custom hooks, written for developers who want cleaner code.

Updated 16 min readMarkdown
React Component Design Patterns Every Developer Should Know

A while ago I noticed something odd about the way many of us learn react hooks. We memorise the names, we copy the examples, we nod along when a talk says the word composition, and then we open a real project and feel strangely lost. The vocabulary was never the problem. What was missing was a way of looking at a screen and deciding where each piece of logic belongs. This article is an attempt to hand you that way of looking, using react design patterns as the lens and one small running example as the map.

You do not need to be an expert to follow along, and you will not need a single line of boilerplate. Everything is explained in plain words, with the kind of examples that stick after you close the tab. If you are comfortable writing a basic component and you have met useState once or twice, you are ready.

Meet the Ticket Dashboard

Every idea in this article will hang off one imaginary project, so let us build a picture of it. Imagine a support ticket dashboard for a small company. It has a list of tickets, a search box, a filter for status, a panel that shows one ticket in detail, and a button that lets an agent reply. Nothing exotic. It is the kind of thing teams build all over the open web every single week, which is exactly why it makes a good teacher.

Now picture the first version. One giant component fetches the tickets, stores the search text, keeps the selected ticket, formats the dates, draws the list and handles the reply button. It works. It even looks fine. But the moment someone asks for a second filter, or a different layout on mobile, or a reply draft that survives a page refresh, the whole thing starts to groan. This is the moment where good react app design either saves you or does not.

Notice what is actually happening in that giant component. It is doing at least five different jobs at once, and every job is tangled with the others. Patterns are simply ways of untangling jobs so that each one can change without disturbing the rest. That is the real meaning of a design pattern in react, and design patterns for react are best treated as options rather than commandments. The deeper react js patterns, the reactjs patterns built on composition and predictable state, have barely moved since the early days.

Drawing Lines Before Writing Code

The most valuable skill in react component development is the one that happens before you type anything. You look at the screen and draw lines. Which part is only showing information? Which part knows where the information comes from? Which part reacts when a human does something?

In our dashboard, a single ticket row is a pure display piece. Give it a subject, a status and a time, and it draws a row. It has no idea whether the data came from a server, a file or a test. That ignorance is a strength. It means you can reuse the row in a search result, in a sidebar and in a printable report without touching it.

The list that contains those rows is different. It decides which tickets are visible, what to show while the data loads and what message appears when nothing matches. It is the thinking layer. Keep thinking and showing apart and you get components that are easy to test, easy to restyle and easy to hand to a teammate, which matters a great deal when you use react for frontend work on a growing team. This split has been around since the early days of React, and hooks did not retire it. They only changed where the thinking lives, because you can now put it in a function instead of a wrapper.

A good react component design usually passes a quick sanity check. Can you describe what this piece is responsible for in one sentence, without using the word and? If the sentence needs an and, you probably have two components trying to share a name.

Slots, Children and the Art of Leaving Room

Our dashboard needs a panel component, the sort of rounded box with a title bar and a body. The tempting approach is to give the panel a long list of switches, such as showCloseButton, showFooter, isCompact and hasBorder. After a month nobody can remember which combinations make sense.

The calmer approach is composition. The panel receives children and renders them inside a frame. If one screen needs a footer, that screen passes a footer. If another needs an action menu in the title bar, that screen passes one. The panel stays small because it never tries to predict the future. React has no real interest in inheritance, and this is why. Putting pieces inside pieces is simply more flexible than extending one piece into another.

Take the idea a step further and you reach compound components, the secret behind almost every react ui component library worth using. A tabs control is made of several parts that must agree about which tab is active. Instead of forcing the user to wire them together, the library hides a little shared context and lets the parts talk quietly behind the scenes. The person writing the screen sees something that reads like ordinary markup. If your dashboard ever needs filters that open and close together, a compound component is how you give your teammates a pleasant tool instead of a puzzle.

The Remembering Problem

Now to state, the part that trips people most often. Anyone who searches for usestate react or react usestate will find a counter. Counters are lovely and almost useless as preparation, so let us use the dashboard instead.

The dashboard needs to remember the search text, the chosen status filter and the selected ticket. These are genuinely independent, so separate useState calls are perfect. The skill lies in what you refuse to store. You might be tempted to keep a second piece of state called filteredTickets, updated whenever the search changes. Resist. The filtered list can be worked out from the full list plus the search text and the filter, every time the component draws itself. Storing it creates two sources of truth, and two sources of truth eventually disagree. Understanding usestate in react js really means understanding what deserves to be state and what is just a calculation wearing a disguise.

There is a second small habit. When the next value depends on the previous one, pass the setter a function rather than a fixed value. React may batch several updates into one, and the number you can see in your closure may already be stale. People who adopt this habit early almost never meet the baffling bugs that get blamed on the library.

Eventually the reply box arrives, and it brings a cluster of related facts. There is the draft text, whether it is sending, whether sending failed, and the message to show if it did. Four pieces of state that change together are an invitation to useReducer. With usereducer in react you describe what happened, such as the draft changed or the send began or the send failed, and one function decides the new state. The component only announces events. The rules live in the reducer, where you can read them in a minute and test them without drawing anything. If someone asks you for a react hooks example that feels realistic, or a react hooks with example walkthrough, a reply box with a clear status story is better than any counter, because you can follow the whole life of the form from the first keystroke to the final success message.

Housekeeping With Effects

State is the friendly half of hooks in react. Effects are the half that needs patience. The dashboard has a clear reason to use one, because tickets live on a server and the component has to go and get them.

An effect is a way of keeping your component in step with something outside React. When you write useeffect react code, you are making a promise that whenever certain values change, a particular piece of work should run again. The list of those values is the dependency array, and it must be honest. Hide a value from it and the effect quietly works with an old copy. Put an unstable object in it and the effect fires on every render. Most of the confusion people attach to the react useeffect hook comes from these two slips, not from the hook being mysterious.

Cleanup is the part many tutorials rush past. Suppose the agent types in the search box and each keystroke asks the server for matches. Responses do not always return in the order they were sent. A slow answer to an earlier keystroke can land after a faster answer to a later one and overwrite the screen with stale results. The cleanup step lets you cancel or ignore the earlier request. Once you view useeffect in react as a pair of start and stop, the useeffect hook becomes something you can reason about.

The performance hooks tend to follow. In plain terms, usecallback react hands you the same function between renders until its dependencies change. That matters when you pass a function down to a child that should not redraw needlessly, or when the function sits in an effect's dependency list. In the many other situations, react usecallback is just extra reading for your teammates. Measure first. A memoised function should always earn its keep.

Turning Habits Into Custom Hooks

By now the dashboard has a few repeated chunks. Two different screens fetch things and track loading and error flags. The search box and the reply box both need to wait a moment after typing before doing anything. A drawer remembers whether it was open the last time you visited. Each chunk is a habit your components keep repeating, and habits are exactly what custom hooks exist to capture.

A custom hook in react is nothing exotic. It is a function whose name begins with use and which calls other hooks inside. When someone learns this, the whole subject of hooks in js suddenly feels less like a rulebook and more like ordinary programming. You are extracting repeated logic into a function, just as you always have, except that this function is allowed to remember things and to run effects.

If you enjoy reading the same topic from a slightly different angle, a longer companion piece is waiting around this corner for a quiet moment.

Back in the dashboard, imagine you pull the fetching routine into a hook that returns the data, a loading flag and an error. Every screen that needs tickets now writes one short line, and a bug fix happens in one place. Pull the waiting routine into another hook and your two text boxes behave identically. Pull the drawer memory into a third and the preference sticks between visits. This is what people mean when they praise react custom hooks, or custom hooks react style. They are small, named and single minded, so reading a component feels like reading a sentence.

A few habits keep your own hooks pleasant. Name them after what they provide, so useTickets beats useFetchAndMaybeSort. Keep each one focused, because a hook that does five jobs is just the original messy component in a new costume. Return a compact and predictable shape. And write a quick test for the logic, which is easy precisely because a hook is only a function. The next hook you write will probably come from the next time you feel the urge to copy and paste, so treat that urge as a gift. Soon custom react logic of your own will feel as ordinary as writing a component.

Sharing Without Shouting

Our dashboard has a theme, a signed in agent and a language setting. These are needed almost everywhere, and passing them through five layers of components would be tiring. This is exactly what context is for.

The danger is enthusiasm. Context makes it easy to share things, so people start sharing everything, including the selected ticket and the search text. Now every component that reads that context draws again whenever any of those values change, and the dashboard feels sluggish for reasons nobody can see. A healthier rule is to keep state close to the components that use it. Lift it only when two neighbours genuinely need to agree, and reach for context only for the few values that are truly global. Developers sometimes call this colocation, and it quietly prevents more performance trouble than any clever trick.

Among the advanced react patterns, you will also hear about render props and higher order components. They are older relatives of the hook approach. A render prop hands you data and lets you decide what to draw, while a higher order component wraps a component to give it extra abilities. You may not write them often, but you will read them in older projects and in libraries, so it pays to recognise their shapes. Treat them as a language you read fluently and speak occasionally, and you will carry the best react js best practices without needing to memorise any slogans.

Where Templates and Design Tools Fit

At some point a teammate will say, why not start from a react template? It is a fair question. A well made react website template, a react js website template or a react app template can save an afternoon of setup and give you routing, folders and sensible defaults. The risk is copying a template and never understanding it. A smarter habit is to treat the template as a worked example. Open it and look for the patterns from this article. Where does it split display from thinking? Where do shared settings live? Which parts could become custom hooks?

Design is the other half of the story. Teams today expect a developer to be comfortable with the work of a react designer, because the line between a mockup and a running screen has become thin. A good react design system gives colours, spacing and type a shared home. A smooth react design tool handoff means a designer can publish components that a developer can rebuild with confidence. This is what makes react website design feel consistent from page to page, and it is why a front end developer who understands both sides is so valuable. If you can build a button, an input and a card that all respect the same tokens, you already think like someone who could lead the react front end of a serious product. And if someone asks whether it is a library or a react web framework, the honest answer is that the label matters far less than the habits you build around it.

The Same Brain on a Smaller Screen

If you ever work on a phone app, you will be pleasantly surprised. Almost everything we discussed travels intact into react native dev work. Components, props, state, effects and custom hooks behave the same way, and the habits around composition and colocation transfer completely. Only the building blocks change, with View and Text instead of div and span.

The stakes, however, are higher. On a phone, needless rendering can show up as dropped frames and a battery that drains faster than it should. That is why react native hooks deserve a bit more care, and why the habits of cleaning up listeners, avoiding heavy work while drawing and keeping lists light matter even more. Many of the react js hooks you wrote for the web can move across with very little change, which is one of the quiet joys of learning this ecosystem.

Talking About It Out Loud

Eventually you will need to explain all this to another human being, usually in an interview. In many Hyderabad teams, the questions are surprisingly consistent. Common react hooks interview questions include the difference between useState and useReducer, why the dependency array exists, how useCallback differs from useMemo, and when a custom hook beats a component. Interviewers rarely want a perfect definition. They want to hear your reasoning.

The best way to practice react is to build something small and finish it. A habit tracker, an expense splitter, a notes app with search or a movie browser will each force you to decide where state lives and when to fetch. Thirty focused minutes a day of react practice beats a heroic weekend once a month, and steady react js practice builds the instincts that no article can hand over. When you follow a react hooks tutorial, try one test. Does the author ever show something going wrong? A lesson without stale values or cleanup is a highlight reel. Type along, break things deliberately, change one line at a time and explain the result out loud. It costs nothing and it separates people who collect certificates from people who collect skills. The same goes for practice react sessions with a friend who plays interviewer. Nothing reveals a gap faster than being asked to explain.

A Calm Way Forward

React is not difficult because the syntax is hard. It is difficult because the decisions are subtle, and each decision is small. Where should this state live? Is this an effect, or just a calculation? Should this logic stay here or become a hook? Answer those questions patiently, one component at a time, and the project stays easy to change.

So the next time you open a component and feel that familiar sinking sensation, remember the ticket dashboard. Draw lines between showing and thinking. Compose instead of piling on flags. Keep state small and honest. Treat effects as housekeeping with a start and a stop. Turn repeated habits into custom hooks, and share through context only when the whole app truly needs it.

Most of all, remember that skill grows through practice and honest feedback, not through bookmarks. Pick one tiny project this week, build it properly and ask someone experienced to read it. If you want a guided route with an instructor and mentor beside you, and you happen to be in Hyderabad, there is a structured React path waiting at this spot whenever you feel ready to begin.

About the author

  • JustAcademy is an industry focused IT training institute helping students, freshers, and working professionals build practical, job ready technology skills. On this blog, we share practical insights, tutorials, coding guides, career advice, and learning resources covering topics such as Full Stack Development, Java, Python, Data Analytics, Software Testing, QA Automation, Cloud Computing, UI/UX Design, and more. Our goal is to make technology easier to learn through practical knowledge, real world examples, and career focused content. Learn. Build. Upskill. Get Job Ready.

No comments yet. Be the first to comment.