React best practice to create multiple components or only one using conditinal rendering

We collided two different approaches how write React components:

1st approach: create different components for different use cases

export default function HeaderForEdit(): ReactNode {
  return (
        <div className="class1 class2 class3">
          <Button icon={back} title={"Go back"} />
          <div>
            <Title>Edit</Title>
            <Subtitle>You can edit this file</Subtitle>
          </div>
        </div>
  );
}

export default function HeaderForCreate(): ReactNode {
  return (
    <div className="class1 class3">
      <div>
        <Title>Create</Title>
      </div>
    </div>
  );
}

The second approach says this is very similar, so merge into one component, add some properties to support conditional rendering:

export default function HeaderForAnything({ icon, icontTitle, title, subtitle }): ReactNode {
  return (
    <div className={icon ? "class1 class2 class3" : "class1 class3"}>
      {icon && <Button icon={icon} title={iconTitle} />}
      <div>
        <Title>{title}</Title>
        {subTitle && <Subtitle>You can edit this file</Subtitle>}
      </div>
    </div>
  );
}

With the proper parameterization this one component could do both.

The pro-s for the 2nd approach are:

  • less components, smaller size of the final bundle
  • it is how react works, its reusable component, can fit for both cases
  • more maintainable, as we should maintain only one component not two

I don’t really know too much about the 1st pro, about the bundle size, but don’t see the 2nd and 3rd option at all. Its of course reusable as it is (in a braver moment we can call it as a “generic” component) – but if we have a 3rd use case, we should add more properties to fit that use case. Also is not readable for me as don’t recognize as the icon option controls exactly what inside this component, for example I don’t add an icon but want to use a subTitle – it cannot. If we modify this component that not the icon but something else controls if the subTitle is rendered or not – its very dangerous for me as should view all the places it is used to discover if it spoils that usage or not.

The 1st approach is much more simpler for me, if we use atomic pattern there are simple reusable components, several, and we combine them into a bigger component, importing only those components which are needed. In this approach almost no extra property is needed because no conditional rendering is used. Also seems much more maintainable, because a component is used in few places only, less chance to spoil a code somewhere else, etc.

But I cannot handle the reasoning that “this is how react works”. So now I’m here: what are the practices and recommendations how to do it in a larger project nowadays?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật