Question

ReactJS cutomization

  • Posted April 11, 2022
  • React

I have a component that is used across different clients in the application. 80-90% of the functionality is common across all clients but 10-15% is customized for each client (there could be UI changes or some functional changes). I don’t want to create a component for every client rather I am looking to create a base component that has all common functionality and only create the 10-15% of functionality that is client specific. What is the best approach for this in ReachJS and Material UI so its easy to maintain over time?

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hello,

I believe that in your case it would be best to have your base component as a parent component and then have children prop to pass children elements directly:

function FancyBorder(props) {
  return (
    <div className={'FancyBorder FancyBorder-' + props.color}>
      {props.children}
    </div>
  );
}

This lets other components pass arbitrary children to them by nesting the JSX:

function WelcomeDialog() {
  return (
    <FancyBorder color="blue">
      <h1 className="Dialog-title">
        Welcome
      </h1>
      <p className="Dialog-message">
        Thank you for visiting our spacecraft!
      </p>
    </FancyBorder>
  );
}

For more information I would recommend checking out this CodePen here:

https://codepen.io/gaearon/pen/ozqNOV?editors=0010

Best,

Bobby