Question

ReactJS cutomization

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?


Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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