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

React router Link tag color is not changing in build environment

I am using tailwind with react and using conditional rendering to change the color of the link tags in the navbar based on different screens. It works fine in the localhost but when I run the build and place it on the server the link’s color remains the same. Here is the code for the link

 <NavLink
            to={`${Routes.main}`}
            className={`m-2 block mt-4 lg:inline-block lg:mt-0  lg:${
              heroSection ? "text-white" : "text-teal-200"
            }`}
          >

What is the reason for it to work on the local environment and not in the build?

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 :

Don’t use string concatenation to create class names:

lg:${heroSection ? "text-white" : "text-teal-200"}

Do dynamically select a complete class name:

${heroSection ? "lg:text-white" : "lg:text-teal-200"}

That means that it is important to avoid dynamically creating class strings in your templates with string concatenation, otherwise PurgeCSS won’t know to preserve those classes.

learn more: Tailwind Optimizing for Production

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