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

Hide the badge number when it is 0 using React and Typescript

I am developing a Badge component. I want to hide the Bade when the number is 0.

I tried this on codesandbox. I am using invisible as a prop. This has a class "invisible". I am not sure how to apply this class when the batchContent is 0. I tried but it’s not working.
Not sure if using useState would help. Please help me with this. Thanks.

Here is my link https://codesandbox.io/s/badgecomponent-ljdq25?file=/src/components/Badge.tsx

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

>Solution :

You could just render it conditionally – display it only if badgeContent is greater than 0.

{Number(badgeContent) > 0 && (
   <span className={`badgeContent`}>
      {displayValue}
   </span>
)}
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