Higher Order Component (HOC) - promoted tag
Ayush Kumar
1 min read
Table of contents
🚀 Higher Order Components
- input is component and output is (modified) component
// FileName: 📂Restaurant Card
const RestaurantCard = ({ data }) => {
....
....
}
export const withPromotedLabel = (RestaurantCard) => {
return (props) => {
return (
<div className='relative'>
<RestaurantCard {...props} />
<p className='absolute top-0 right-0 bg-teal-300'>Promoted</p>
</div>
)
}
}
export default RestaurantCard;
import RestaurantCard, { withPromotedLabel } from "../components/RestaurantCard";
import { useEffect, useState } from "react";
const RestaurantCardPromoted = withPromotedLabel(RestaurantCard);
...
...
renderResList.map((data) => (
(false) ? <RestaurantCard key={data.id} data={data} />
: <RestaurantCardPromoted key={data.id} data={data} />
))
0
Subscribe to my newsletter
Read articles from Ayush Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Ayush Kumar
Ayush Kumar
A passionate MERN Stack Developer from India I am a full stack web developer with experience in building responsive websites and applications using JavaScript frameworks like ReactJS, NodeJs, Express etc.,