0

I'm trying to improve my React code, and I would like to know if instead of duplicating components with different variables, there was a possibility to create a single component and modify the variables?

 <Card>
       <CardTitle>Hey</CardTitle>
       <CardTexte>Text</CardTexte>
       <CardButton>Yo</CardButton>
     </Card>

     <Card>
       <CardTitle>Hey</CardTitle>
       <CardTexte>Text</CardTexte>
       <CardButton>Yo</CardButton>
     </Card>

    <Card>
    <CardTitle>Hey</CardTitle>
    <CardTexte>Text</CardTexte>
    <CardButton>Yo</CardButton>
    </Card>

Thanks for your time

1 Answer 1

2

If your components have the same sub-components and same style, you can use a wrapper to create a new component.

const WrapperComponent = ({ title, text, buttonText }) => {
  return (<Card>
    <CardTitle>{title}</CardTitle>
    <CardTexte>{text}</CardTexte>
    <CardButton>{buttonText}</CardButton>
    </Card>);
};
Sign up to request clarification or add additional context in comments.

1 Comment

And how to call this component ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.