7 Best React Design Patterns That Every Developer Should Know
Last Updated :
24 Apr, 2025
Writing code is one thing and writing reusable and modular code is another. Design patterns help us achieve the latter. Currently, React is one of the most widely used UI libraries and with the help of design patterns, developers can solve a lot of problems and write high-quality React code.
Design patterns are the most effective solutions to the common software development challenges that a developer may face. Often, there are multiple solutions to a single problem. They all solve the problem, but some may create issues when more complexity is introduced in the code.
Need to Use Design Patterns in React
Some common challenges that a React developer faces are:
- Creating reusable components
- Uncontrolled and controlled components in form handling
- Reusing complex logic between multiple components
To solve the above issues, we need React design patterns.
7 Best React Design Patterns That Every Developer Should Know
Well, React is all about building things in a smart, organized way. These design patterns are like handy guides that help you do just that. Whether you're new to React or a seasoned coder, these React Design patterns are like your trusty tools to make your code not just work but work really well. Soo let's deep dive into each react pattern closely.
1. Layout Components Pattern
Layout components are those components that are responsible for arranging other components on a page. Basically, they determine how the components should look on the page. In this pattern, we split the layout and the child component, so that making changes in the layout component won’t affect the child. This maintains the separation between the two components.
This pattern provides more flexibility in how the components may be used in the future.
Let’s create a split screen by creating the layout component first.
Example:
JavaScript
export const SplitScreenLayout = ({ left, right }) => {
return (
<div style={{ display: "flex" }}>
<div style={{ flex: 1 }}>{left}</div>
<div style={{ flex: 1 }}>{right}</div>
</div>
);
};
In the above code, there is “SplitScreenLayout” which is a layout component (parent) and it is going to display two children: left and right.
Example:
JavaScript
const Left = () => {
return <div>Display on the left side</div>;
};
const Right = () => {
return <div>Display on the right side</div>;
};
In the above code, we have defined “Left” and “Right” as the two components that we are going to display on the page as a split screen. Now, we can use both the “Left” and “Right” components inside the “SplitScreenLayout” component.
Example:
JavaScript
export default function App() {
return (
<>
<SplitScreenLayout
left={<Left />}
right={<Right />}
/>
</>
);
}
Output:

2. Conditional Rendering Pattern
In software development, a lot of times a developer has to display different components based on different conditions.For example, if the logged-in user is an admin, show its designation as “Admin” on the page. And if the logged-in user is a simple user, show its designation as “User”.
This is where React conditional rendering comes in.
Example:
JavaScript
export default function App() {
let [products, setProducts] = useState([]);
useEffect(() => {
// fetch a list of products from the server
}, [])
return (
<div className="App">
<h1>Products</h1>
{
products.length > 0 ? (
// do something
) : (
<p>No products</p>
)
}
</div>
);
}
In the above code, a list of products is being fetched in the useEffect hook when the component first mounts and the list is assigned to the “products” state variable. If there is at least one item in the product list, we are doing something in the code. But if there is no item in the list, we are displaying “No products”.
3. Higher Order Components (HOCs) Pattern
HOCs are functions that take a component and return a new component. They help us reuse complex code logic across our application. We don’t need to create two separate components containing similar logic.
Example:
JavaScript
export const printProps = (Component) => {
return (props) => {
console.log(props);
return <Component {...props} />
}
}
The HOC, printProps, starts with a small letter, unlike a functional component because in most cases, we don’t display them inside JSX. We return a new component by taking its props and returning some JSX. In our case, the component itself with all of its props.
That returned component is called SomeComponent, which will just display “I am SomeComponent” on the page.
Example:
JavaScript
export const SomeComponent = () => {
return (
<div>I am SomeComponent</div>
)
}
Below is how we are using the HOC to print the props on the console with the help of SomeComponent.
Example:
JavaScript
export default function App() {
const NewComponent = printProps(SomeComponent);
return (
<div>
<NewComponent
prop1="The value of prop1"
prop2="The value of prop2"
/>
</div>
);
}
We have created a wrapper called “NewComponent” around “SomeComponent” that will display the props on the console given below.
Output:

4. Provider Pattern
Imagine you are building a complex application with a lot of components and their states. How do you pass those states to the end component without involving multiple components in between? To solve this problem, React introduced the provider pattern. The provider pattern shares data globally across the application between various components.
There are multiple state management libraries like Redux, but React provides Context API out of the box to manage state.
Example:
JavaScript
export const Context = createContext();
export const ContextProvider = ({ children }) => {
const [number, setNumber] = useState(0);
useEffect(() => {
setNumber(number + 1);
}, []);
return (
<Context.Provider value={{number}}>
{children}
</Context.Provider>
);
};
We have created a context where we have added a number state that increments to 1 when the component first mounts.
To use the number state variable, we need to wrap the whole app with the context provider.
Example:
JavaScript
export default function App() {
return (
<ContextProvider>
<BaseComponent />
</ContextProvider>
);
}
Now, with the help of BaseComponent, we can display the number state on the page.
Example:
JavaScript
export const BaseComponent = () => {
const { number } = useContext(Context);
return <div>{number}</div>;
};
With the Context API, we can use any state variable defined inside the context in any component.
5. Presentational and Container Components Pattern
Presentational and Container components separate the application layer from the view layer. The Presentational component deals with how the component will look on the page, while the container component handles the data, i.e., what will display on the page.
Example: Presentational Component
JavaScript
export const DisplayComments = ({ list }) => {
return (
list &&
list.map((item) => {
return (
<div key={item.id}>
<p>{item.body}</p>
</div>
);
})
);
};
The above component just displays a list of comments on the page. It doesn’t handle the data fetching logic.
Example: Container Component
JavaScript
export const Comments = () => {
const [comments, setComments] = useState([]);
useEffect(() => {
(async () => {
const response = await axios.get("https://jsonplaceholder.typicode.com/posts/1/comments");
setComments(response.data);
})();
}, []);
return <DisplayComments list={comments} />;
};
The above container component fetches the comments of a post and returns the presentational component with the comments passed as props.
6. Render Props Pattern
A render prop is basically a prop on a component whose value is a function that returns JSX. Here, the component calls the render prop instead of rendering anything. Therefore, there’s no rendering logic being implemented.
Example:
JavaScript
const Username = (props) => props.render();
We have created a Username component whose job is to render whatever we pass to its props, in our case, the name of a person.
Example:
JavaScript
export default function App() {
return (
<div>
<Username render={() => <h1>John</h1>} />
<Username render={() => <h1>Charles</h1>} />
</div>
);
}
We have used the “Username” component to display the names of two different people. This pattern increases the reusability of the component even more.
7. Compound Pattern
A compound pattern can be referred to as multiple components that are combined together to serve a common function. For example, select tag and option tag in HTML are responsible for creating dropdown menus.
Example:
JavaScript
<Tabs>
<header>
<ul>
<li>
<Tab id="a">
<button>Tab 1</button>
</Tab>
</li>
</ul>
</header>
<main>
<TabPanel active="a">
<div>
Tab 1 Panel
</div>
</TabPanel>
</main>
</Tabs>
In the above code, there’s a “Tab” component that renders a tab panel when we click on the tab button. Here, multiple components are combined together to create one compound component.
Conclusion
React design patterns are some of the most useful techniques that provide benefits to developers in order to write reusable code.We discussed the 7 best design patterns to use in React, and in order to improve our code, it is important to use the design patterns along with the React best practices. The choice of design pattern should be context-dependent and should align with the specific requirements. By combining design patterns and React best practices, you can write cleaner, more maintainable, and efficient code.
Similar Reads
7 React Best Practices Every Web Developer Should Follow
React...the most popular library of Javascript for building user interfaces. For developers, this library is one of the favorite libraries to build any kind of beautiful applications. Learning React might be easy for you. You start using React and you start developing an application. You create one
8 min read
HTML vs. React: What Every Web Developer Needs to Know
In the world of web development, two prominent names often pop up in conversations: HTML and React. As a beginner web developer, you're probably wondering which one to choose and why. This comprehensive guide aims to shed light on the differences between HTML and React, their functionality, performa
8 min read
Essential things to know as React Developer
React is an open-source JavaScript library used to create user interfaces in a declarative and efficient way. It is a component-based front-end library responsible only for the view layer of a Model View Controller(MVC) architecture. React is used to create modular user interfaces and promotes the d
8 min read
How to Prepare Design Components For Front-End Developers?
There are ideal processes and tools in a parallel universe that allow you to create design layouts without a single flaw or omission. It must be a beautiful universe. But until scientists invent ways to travel between worlds, developers will have to deal with layouts that have flaws. A designer can
12 min read
How to Become a React Developer?
A React Developer is a specialized software developer focused on building dynamic and responsive user interfaces using React, a popular JavaScript library. React, developed and maintained by Facebook, has become a go-to tool for developers worldwide due to its efficiency and flexibility in building
11 min read
Top Design Patterns Interview Questions [2024]
A design pattern is basically a reusable and generalized solution to a common problem that arises during software design and development. Design patterns are not specific to a particular programming language or technology instead, they provide abstract templates or blueprints for solving recurring d
9 min read
Most Common Mistakes That React Developers Make
React is a JavaScript library for building user interfaces. During the process of developing a React app, we made a lot of common mistakes. Thatâs not a problem that we make mistakes, but itâs always a problem more than anything else if we donât learn something by making a mistake. In this article,
5 min read
React.js Blueprint Non-ideal state Component Props
BlueprintJS is a React-based UI toolkit for the web. This library is very optimized and popular for building interfaces that are complex data-dense for desktop applications. NonIdealState Component provides a way for users to inform the user that some content is unavailable. There are three types of
3 min read
Top 7 Best Books to Learn React JS
You might have heard the saying, Hard-work is the key to success, which might have been relative in the past, but now the scenario has changed. Now the world has developed so much that only doing hard wonât guarantee success; you will have to do smart work. ReactJs is the most popular front-end libr
6 min read
Why should keys be unique in a React list?
In React, keys should be unique within a list to help React efficiently identify and update elements during rendering. Unique keys enable React to distinguish between different list items and optimize re-rendering, ensuring accurate component state management and preventing unexpected behaviour or e
4 min read