This website uses cookies to ensure you get the best experience on our website.

Skip to content
LOGO
  • Company

    About IGNEK

    Learn about our story and our mission.

    Careers

    We're hiring!

    We always looking for talented peoples. Join our team!

    Blogs

    The latest industry news, updates and info.

    Case Studies

    Take a closer look at the projects we've delivered

    Webinar

    Watch our latest organized webinar

    Get in touch with our HR team

    • hr@ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Custom Enterprise Portal Development for flawless Solutions

    Dedicated Development Team

    Expand Teams, Optimize Development with Our Expertise

    Back-end Development

    Empowering your digital presence with robust backend development expertise

    Front-end Development

    Crafting engaging user experiences through expert frontend development

    Digital Transformation

    Embrace digital transformation by modernizing process

    SaaS Development

    Transform your business with SaaS Innovative Solutions

    Technologies

    Liferay Services

    Development & Customization

    Theme

    Upgradation

    Migration

    Proof of Concept

    Performance Tunning

    Architecture

    Support & Maintenance

    E-commerce

    Expert Advice

    React Services

    Enterprise Development

    Custom Application

    Single Page Application

    Architecture

    API Integration

    Migration

    Consulting

    Maintenance & Support

    Spring Boot Services

    Web Service

    MVC Web Development

    API Integration

    Security

    Migration

    Microservices

    Support & Maintenance

    AEM Services

    Consulting Service

    Site Development

    Migration & Upgradation

    Integration

    Maintenance & Support

    Custom Solutions

    Content Management

    Team Augementation

  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Transforming industries through cutting edge SaaS solutions.

    Customer Portal : Boost Business Productivity

    Streamline operations and enhance productivity with our Customer Portal solution.

    Liferay Based Intranet Portal

    Internal portal for company communication, collaboration and resources

    Integration

    Matomo Integration with Liferay

    Integrate Matomo to enable user interactions seamlessly.

    Microsoft Teams integration with Liferay

    Integrate to enable seamless collaboration, messaging within your portal.

    Jira Integration With Liferay

    Optimizes business operations by integrating with Jira.

  • Hire Us

    Liferay

    Get expert Liferay developers for seamless portal solutions.

    React JS

    Get expert ReactJS developers for dynamic web solutions.

    Web Developer

    Get custom web solutions from IGNEK's expert developers.

    Spring Boot

    Get top-notch Spring Boot developers for your project success!

    Healthcare

    Get top Healthcare Developers for cutting-edge medical software.

    MERN Stack

    Get expert MERN developers from IGNEK for custom, innovative project solutions.

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@ignek.com
    • +91 6351576580
    • info@ignek.com
    • Ahmedabad, Gujarat, India – 382470
SCHEDULE CALL
  • COMPANY
    • About
    • Case Studies
    • Blogs
    • Career
    • Webinar
  • SERVICES
    • Enterprise Portal Development
    • Dedicated Development Team
    • Back-end Development
    • Front-end Development
    • Digital Transformation
    • SaaS Development
  • SOLUTION
    • Customer Portal:  Boost Business Productivity
    • SaaS : Software as a Service
    • Liferay Based Employee Intranet Portal
  • TECHNOLOGY
    • Liferay Services
      • Liferay Development and Customization
      • Liferay Theme Development Service
      • Liferay DXP 7.4 Upgrade
      • Liferay Migration
      • Liferay Proof Of Concept
      • Liferay Performance Tuning
      • Liferay Architecture Design Service
      • Liferay Support And Maintenance Service
      • Liferay Ecommerce Development
      • Liferay Expert Advice
    • ReactJS Services
      • ReactJS Enterprise Application Development
      • ReactJS Custom Application Development
      • ReactJS Single Page Application Development (SPA)
      • ReactJS Applications Architecture
      • ReactJS API Integration
      • ReactJS Migration
      • ReactJS Consulting
      • ReactJS Maintenance and Support
    • Spring Boot Services
      • Spring Boot Web Development Service
      • Spring MVC Web Development
      • Spring Boot API Integration Service
      • Spring Boot Security
      • Spring Boot Migration Service
      • Spring Boot Microservices
      • Spring Boot Support & Maintenance Service
    • AEM Development Services
      • AEM Consulting Services
      • AEM Site Development
      • AEM Migration & Upgradation
      • AEM Integration Services
      • AEM Maintenance & Support
      • AEM Content Management
      • Custom AEM Solutions
      • AEM Team Augmentation
  • INTEGRATION
  • HIRE US
    • Hire Liferay Developer
    • Hire ReactJS Developer
    • Hire Spring Boot Developer
    • Hire Healthcare Developer
    • Hire Web Developer
    • Hire MERN Stack Developer
  • CONTACT US
  • Company

    About IGNEK

    Careers

    We're hiring!

    Blogs

    Case Studies

    Webinar

    Get in touch with our HR team

    • hr@ignek.com
    • +91 93284 95160
    • Ahmedabad, Gujarat, India – 382470
  • Services

    Enterprise Portal Development

    Dedicated Development Team

    Back-end Development

    Front-end Development

    Digital Transformation

    SaaS Development

    Technologies

    Liferay Liferay Services
    • Development & Customization
    • Theme
    • Upgradation
    • Migration
    • Proof of Concept
    • Performance Tuning
    • Architecture
    • Support & Maintenance
    • E-commerce
    • Expert Advice
    React React Services
    • Enterprise Development
    • Custom Application
    • Single Page Application
    • Architecture
    • API Integration
    • Migration
    • Consulting
    • Maintenance & Support
    Spring Boot Spring Boot Services
    • Web Service
    • MVC Web Development
    • API Integration
    • Security
    • Migration
    • Microservices
    • Support & Maintenance
    AEM AEM Services
    • Consulting Service
    • Site Development
    • Migration & Upgradation
    • Integration
    • Maintenance & Support
    • Custom Solutions
    • Content Management
    • Team Augmentation
  • Solution

    Ready for digital excellence

    In our rapidly evolving world, businesses are always on the lookout for fresh ways to improve their operations and connect with their audiences.

    Contact US

    Solutions

    SaaS : Software As A Service

    Customer Portal : Boost Business Productivity

    Liferay Based Intranet Portal

    Integration

    Matomo Integration with Liferay

    Microsoft Teams integration with Liferay

    Jira Integration With Liferay

  • Hire Us

    Liferay

    React JS

    Web Developer

    Spring Boot

    Healthcare

    MERN Stack

    Why Hire Developers From IGNEK ?

    • Certified Developer
    • Transparent Communication
    • Flexible Hiring Modals
    • Fully Signed NDA
    • Cost Effective
    • Easy Exit Policy

    Get in touch with our Sales team

    • sales@ignek.com
    • +91 6351576580
    • IGNEK
    • Ahmedabad, Gujarat, India – 382470
  • SCHEDULE CALL

React design patterns: writing clean and maintainable code

  • ReactJS
  • July 1, 2025

Share On :

Introduction

React provides developers with many options to create application designs through its versatile nature. The many ways React facilitates development are beneficial, but cause codebases to become complicated for scaling and testing, and maintenance. The introduction of design patterns generates a solution to these challenges.

This blog examines critical React design patterns which developers should use to develop clean, sustainable and expansible codebases. These practices will enable solo coders and teamwork to develop robust professional React applications.

Prerequisites
  • Node.js and npm

  • React

  • Typescript

  • React Hooks and Custom Hooks

  • Higher Order Functions

Why Use React Design Patterns?

Developer solutions to recurrent software development difficulties appear as reusable abstract patterns. In the case of React.

  • These coding practices enhance readability in addition to enabling smooth teamwork between different development teams.

  • Uniform structures will support bug reduction.

  • Elements of the system should have the capacity for reuse and extensive testing.

  • The design pattern standardizes code structure to enhance the process of refactoring and new developer onboarding.

Presentational and Container Components Pattern :

The software principle of separation of concerns achieves excellent implementation support in React through its introduction of Presentational and Container components.

  • UX elements receive attention through presentational components that define visual aspects (UI).

  • Such components concentrate on system operation and handling of logical and data elements.

Presentational Component(UI) :

				
					// PresentationalComponent.tsx

type UserCardProps = {
  name: string;
  email: string;
};

const UserCard: React.FC<UserCardProps> = ({ name, email }) => (
  <div className="card">
    <h3>{name}</h3>
    <p>{email}</p>
  </div>
);

export default UserCard;

				
			

Container Component(Logic) :

				
					// ContainerComponent.tsx
import UserCard from '../components/UserCard';
import { useEffect, useState } from 'react';

type User = {
  name: string;
  email: string;
};

const UserCardContainer = () => {
  const [user, setUser] = useState<User | null>(null);

  useEffect(() => {
    fetch('/api/user')
      .then((res) => res.json())
      .then(setUser);
  }, []);

  return user ? <UserCard name={user.name} email={user.email} /> : <p>Loading...</p>;
};

export default UserCardContainer;

				
			

Higher-Order Components :

An HOC functions through a process where it accepts a component to produce another component that inherits additional functionality.

  • The behavior addition process does not impact the wrapped component.
  • The framework provides context-based injection for adding props which include authorization and theme features.
  • The implementation of permission wrappers and analytics hooks as well as other related functionality.
				
					// hoc/withAdminGuard.tsx

import React from 'react';
type WithAdminProps = {
  isAdmin: boolean;
};
export function withAdminGuard<P extends object>(
  WrappedComponent: React.ComponentType<P>
) {
  return ({ isAdmin, ...props }: WithAdminProps & P) => {
    if (!isAdmin) return <p>Access denied</p>;
    return <WrappedComponent {...(props as P)} />;
  };
}

				
			

Usage :

				
					//components/Dashboard.tsx

const Dashboard = () => <h1>Admin Dashboard</h1>;

export default withAdminGuard(Dashboard);

				
			

Custom Hooks :

Hooks represent the main benefit of modern React applications. Rephrase the complex effects and state management logic from components by moving them into customizable hooks known as custom hooks.

  • All custom hooks begin with use (such as useAuth and useFetch, and useFormState).
  • When using Hooks in your applications, always maintain their purity while allowing defined side effects to occur when necessary.
  • Documentation of future input and output will enhance the developer experience.
  • Custom hooks establish themselves as the main approach for creating reusable logic components.
				
					// hooks/useWindowSize.ts
import { useEffect, useState } from 'react';

type WindowSize = {
  width: number;
  height: number;
};

export const useWindowSize = (): WindowSize => {
  const [size, setSize] = useState<WindowSize>({
    width: window.innerWidth,
    height: window.innerHeight,
  });

  useEffect(() => {
    const handleResize = () =>
      setSize({ width: window.innerWidth, height: window.innerHeight });
    window.addEventListener('resize', handleResize);
    return () => window.removeEventListener('resize', handleResize);
  }, []);

  return size;
};

				
			

Compound Components :

Compound components built with React Context represent an elegant solution to share internal state between related components that avoid the need for drilling props.

				
					// components/Tabs.tsx
import React, { createContext, useContext, useState } from 'react';

type TabsContextType = {
  activeIndex: number;
  setActiveIndex: (index: number) => void;
};

const TabsContext = createContext<TabsContextType | undefined>(undefined);

export const Tabs = ({ children }: { children: React.ReactNode }) => {
  const [activeIndex, setActiveIndex] = useState(0);
  return (
    <TabsContext.Provider value={{ activeIndex, setActiveIndex }}>
      <div className="tabs">{children}</div>
    </TabsContext.Provider>
  );
};

export const TabList = ({ children }: { children: React.ReactNode }) => (
  <div className="tab-list">{children}</div>
);
export const Tab = ({ index, children }: { index: number; children: React.ReactNode }) => {
  const context = useContext(TabsContext);
  if (!context) throw new Error('Tab must be used within Tabs');

  const isActive = context.activeIndex === index;
  return (
    <button onClick={() => context.setActiveIndex(index)} className={isActive ? 'active' : ''}>
      {children}
    </button>
  );
};

export const TabPanel = ({ index, children }: { index: number; children: React.ReactNode }) => {
  const context = useContext(TabsContext);
  if (!context || context.activeIndex !== index) return null;
  return <div className="tab-panel">{children}</div>;
};

				
			

Render Props :

A single prop object allows us to replace multiple individual parameter passes by combining related values.

Using props as an object simplifies code structure and improves maintainability because it allows transmission of various connected values to a component.

				
					// components/MouseTracker.tsx
import { useState } from 'react';

type MouseProps = {
  render: (x: number, y: number) => React.ReactNode;
};

export const MouseTracker: React.FC<MouseProps> = ({ render }) => {
  const [coords, setCoords] = useState({ x: 0, y: 0 });

  return (
    <div
      style={{ height: '100px', border: '1px solid black' }}
      onMouseMove={(e) => setCoords({ x: e.clientX, y: e.clientY })}
    >
      {render(coords.x, coords.y)}
    </div>
  );
};

				
			

Usage :

				
					<MouseTracker render={(x, y) => <p>Mouse at ({x}, {y})</p>} />
				
			

Controlled Component :

Functional forms require slight attention during their implementation. The value within the controlled input exists in the React state directly.

Uncontrolled components maintain their state inside the DOM while exposing this state through ref.

Controlled represents data that is more predictable and simpler to debug. The performance advantages favor uncontrolled elements when dealing with big forms and external integration points.

The most effective method involves controlled input for user-generated data alongside uncontrolled input for imported and read-only data.

				
					// components/ControlledInput.tsx
import { useState } from 'react';

const ControlledInput = () => {
  const [value, setValue] = useState('');

  return (
    <input
      value={value}
      onChange={(e) => setValue(e.target.value)}
      placeholder="Type here..."
    />
  );
};

				
			

Use TypeScript :

Through typed functionality, TypeScript enables JavaScript users can discover errors in advance while developing code that remains easy to understand. Defining component data requirements enables better reliability and simplified maintenance of your React application through TypeScript.

Frontend Setup in React : 

We’ll write the code to get a better understanding of React code patterns:

Step-by-step Implementation

  • Create a React App :

Let’s create a React app using the following command :

				
					//Create a react app using the following command

npx create-react-app react-code-pattern --template typescript
				
			

 After the setup is complete, navigate to your project folder :

				
					// Navigate to the project folder
 cd react-code-pattern
 npm start
				
			

This will start the development server, and you will be able to visit the app at http://localhost:3000.

  • Project Structure :

Make sure your project has the following folder structure :

Image1

You can find the file codes in their respective section above.

Anti-Patterns to Avoid :

Our discussion of well-known patterns should include a mention of these problematic patterns.

  • Props drilling too deep
  • A requirement for maintaining clean React code involves achieving clear code alongside capabilities for future expansion.
  • Overusing any in TypeScript
  • Ignoring cleanup in useEffect
  • State items that do not belong together should not be stored within a single useState hook call.
Conclusion

A requirement for maintaining clean React code involves achieving clear code alongside capabilities for future expansion. Your code achieves lower maintenance costs with enhanced reliability due to the proper implementation of container components as well as custom hooks and compound components when using TypeScript. The adoption of proper techniques starts with small-scale testing to be used in future maintenance operations.

Explore Our Services

Discover how we can help your business thrive, whether you’re running a small startup, an SME, or a large enterprise. We’re here to understand your unique needs and goals, offering the expertise and resources to support your journey to success.
Stay informed about our ReactJS services and updates by subscribing to our newsletter—just fill in the details below to subscribe.

Loading
Loading...

Related Blogs

July 19, 2024
Simplifying State with Context API
Simplifying State with Context API
August 30, 2024
Simplifying Global State in React with useContext and useReduce
Simplifying Global State in React with useContext and useReducer
November 14, 2024
React Insights Choosing Between useLayoutEffect and useEffect
React Insights : Choosing Between useLayoutEffect and useEffect
Loading...

Featured Projects Portfolios

November 27, 2023
Government Job Platform User-Friendly, Secure and Scalable
Government Job Platform : User-Friendly, Secure, and Scalable
October 4, 2023
Telemedicine Appointment & Health Record Portal
Telemedicine Appointment & Health Record Portal
November 29, 2024
Employee Intranet Portal for Government Entity
Employee Intranet Portal for Government Entity

Digital Solutions for Your Business with IGNEK

4.9

5.0

5.0

5.0

LOGO

Making the world a better place through constructing elegant hierarchies

COMPANY

  • About
  • Career
  • Case Study
  • Blogs

SERVICES

  • Enterprise Portal Development
  • Dedicated Development Team
  • Back-end Development
  • Front-end Development
  • Digital Transformation
  • SaaS Development

HIRE US

  • Liferay
  • Spring Boot
  • ReactJS
  • Healthcare
  • MERN Stack
  • AEM

CONTACT

  • info@ignek.com
  • info@ignek.com
SALES
  • sales@ignek.com
  • (+91) 635 157 6580
CAREER
  • hr@ignek.com
  • (+91) 932 849 5160
  • E 910-912, Ganesh Glory 11, Jagatpur Road, SG Highway, Ahmedabad, Gujarat - 382470

© 2018-2025 IGNEK, Inc. All rights reserved

Linkedin Facebook X-twitter Instagram