---
title: "ReactJS | Higher-Order Components"
url: "https://magecomp.com/blog/reactjs-higher-order-components/"
date: "2023-05-24T12:33:10+00:00"
modified: "2025-02-27T09:25:38+00:00"
author:
  name: "Bharat Desai"
  url: "https://magecomp.com"
categories:
  - "ReactJS"
word_count: 303
reading_time: "2 min read"
summary: "Hello React Friends,"
description: "In ReactJS, Higher-Order Component allows you to enhance the behavior of a component by wrapping it with another component. Learn more"
keywords: "ReactJS"
language: "en"
schema_type: "Article"
related_posts:
  - title: "ReactJS | useContext Hook with Example"
    url: "https://magecomp.com/blog/reactjs-usecontext-hook/"
  - title: "ReactJS | Understanding State and Lifecycle"
    url: "https://magecomp.com/blog/reactjs-state-and-lifecycle/"
  - title: "ReactJS | useCallback Hook with Example"
    url: "https://magecomp.com/blog/reactjs-usecallback-hook-with-example/"
---

# ReactJS | Higher-Order Components

_Published: May 24, 2023_  
_Author: Bharat Desai_  

![ReactJS Higher-Order Components](https://magecomp.com/blog/wp-content/uploads/2023/05/ReactJS-Higher-Order-Components-1024x512.webp)

**Hello React Friends,**

In this article, we will go through the ReactJS HOC concept, why to use them, and how to use them in ReactJS with an example.
So let’s get started with ReactJS Higher-Order Components.
[![React js](https://magecomp.com/blog/wp-content/uploads/2025/02/React-js-CTA-2.webp)](https://magecomp.com/hire-reactjs-developer.html)

## What are Higher-Order Components or HOC in React?
Higher-order components or HOC is the advanced method of reusing the component functionality logic in the project. It simply takes the original component and returns the enhanced component. HOC uses the DRY (don’t-repeat-yourself) programming principle, which is very important while building an application or writing code.
## Reason to use Higher-Order Components in React:
- Easy to handle- Get rid of copying the same logic in every component- Makes code optimized and more readable
## Syntax of Higher-Order Components in React:
```
const EnhancedComponent = higherOrderComponent(OriginalComponent);
```

## [![React js](https://magecomp.com/blog/wp-content/uploads/2025/02/React-js-CTA-3.webp)](https://magecomp.com/services/contact-us/)

## Example of Higher-Order Components in React:
```
import React, { useState } from 'react'
const HOC = (OriginalComponent)=>{
    function NewComponent () {
        const [Value, setValue] = useState(0)
        const handleClick = () =>{
            console.log(2)
            setValue(Value + 2)
        }
        return <OriginalComponent handleClick={handleClick} Value={Value} />
    }
    return NewComponent
}
export default HOC
import React, { useState } from 'react'
import HOC from './HOC'
const Person1 = ({Value, handleClick}) => {
    return (
        <>
            Person1: {Value}            <button onClick={()=> handleClick()}> Count number </button>
        </>
   )
}
export default HOC(Person1)
import React from 'react'
import HOC from './HOC'
const Person2 = ({handleClick, Value}) => {
    return (
        <>
            Person2 : {Value}            <button onClick={()=> handleClick()}> Count number </button>
        </>
    )
}
export default HOC(Person2)
```

## Conclusion:
Hence, this was all about Higher-Order Components in ReactJS. If you face any difficulty, kindly share it with me through the comment box. Connect with [**ReactJs Developers**](https://magecomp.com/hire-reactjs-developer.html) and learn more.
[![React js](https://magecomp.com/blog/wp-content/uploads/2025/02/React-js-CTA-4.webp)](https://magecomp.com/hire-reactjs-developer.html)

Spread the tutorial with your friends to help them learn about Higher Order Components in ReactJS.
**Happy Coding!**


---

_View the original post at: [https://magecomp.com/blog/reactjs-higher-order-components/](https://magecomp.com/blog/reactjs-higher-order-components/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-08-12 17:51:58 UTC_  
