Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I enable and hide [list, button, images,..etc ]by using props

so this is the component:

<ReusedHeader
  H1headerGray="text... "
  H2headerRed="text2 ! "
  pheader="p1"
  getStarted="button text1"
  hrefab="button url 1"
  whatWeDo="button text2"
  hrefbb="button url 2"
  imageSrc="image url"
/>;

the list in the component :

<li className=" hover:ring active:ring-4 w-full flex items-center justify-center px-8 py-3 border border-transparent text-base font-medium rounded-md text-white bg-red-600 hover:bg-red-700 md:py-4 md:text-lg md:px-10">
  {getStarted}
</li>

And this component I will use in many places; in some places, I want the component without buttons;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

how can I enable and disable buttons if possible?

>Solution :

You can just pass the needed props and handle the logic within the component

const ReusedHeader = ({buttonsEnabled=true}) => {
    if(buttonsEnabled){ // return something }
    else { // return something else }
}

Or modify the onClick if you want the same markup without onClick functionality.

onClick={buttonsEnabled? onClick : undefined}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading