how to dynamically add classes in jsx with a combination of tailwind and regular classes

Why is it that in Nextjs 14 (ReactJS 18), when I conditionally assign css classes within a jsx code like this:

 <Swiper
  className={lightbox ? 
"swiperLightbox h-[80%] md:h-[70vh] z-50" :
 "swiperMain h-[21vmax] rounded-xl"} 
 >

the element has both classes swiperMain and swiperLightbox correctly when the lightbox condition is true, along with the other Tailwind classes?

And when the lightbox condition is false, it only includes the swiperMain class and the Tailwind classes as expected.

Answer №1

<Swiper className={[
     "swiperMain h-[21vmax] rounded-xl",
     lightbox ? "swiperLightbox h-[80%] md:h-[70vh] z-50" : "",
   ].join(" ")}>
 </Swiper>

Hopefully this solution resolves your issue.

Thank you

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to prevent memory leaks in useEffect on React hooks

I've implemented the useEffect hook to fetch data from the server and display it in a list. However, when I try to sign up, I encounter the following warning message: Can't perform a React state update on an unmounted component. This is a no-op ...

Three divs are positioned within the parent element and collectively fill the entire height. The first and last div have varying

I attempted to replicate the design shown in the image below: https://i.sstatic.net/Q7sTI.png Initially, I was successful in achieving this using JavaScript. However, when attempting to recreate the same effect using only CSS without any JavaScript, I en ...

Tips for effectively utilizing the overflow:auto property to maintain focus on the final

I am working on a Todo App and facing an issue where the scrollbars don't focus on the bottom of the page when adding a new element. How can this problem be resolved? https://i.stack.imgur.com/IzyUQ.png ...

Optimize Your Website for Various Screen Sizes

Can anyone assist with centering my webpage on small screen sizes? Everything looks good at the normal width of 989px, but once it shrinks, it shifts to the left and leaves excess white space on the right. I've tried various methods to correct this is ...

Facing Issues with Next-Auth and FaunaDB Integration: Troubleshooting Session Errors in

I have successfully implemented Next-Auth with FaunaDB in my NextJS project. It is working well in my production environment, but I am facing issues in my development environment which is using the Fauna Dev docker container instead of the cloud-based data ...

Running "react-script build" is causing an issue when trying to deploy to Heroku

Struggling with deploying create-react-app on Heroku within a Node/Express server. The heroku postbuild script is throwing an error related to react-script build. As a frontend developer new to backend, I lack knowledge about Heroku deployments. ...

Mouse position-based scrolling that preserves click events in the forefront while scrolling

Within a larger div, I have a very wide inner div that scrolls left and right based on the position of the mouse. I found the code for this from an answer at There are two transparent divs above everything else, which capture the mouse position to determ ...

How can you tap into local storage in CSS while utilizing a chrome extension?

Can I access local storage from a Chrome extension's options file using CSS? Is it possible to use JavaScript to define a variable that can be utilized in CSS, or is local storage only accessible through JavaScript? If local storage is restricted to J ...

Error: Cannot access 'muiName' property as it is undefined

i am trying to display the elements of an array within a custom card component in a grid layout. However, when the page loads it freezes and the console shows "Uncaught TypeError: Cannot read property 'muiName' of undefined" custom car ...

Upgrading from Material UI Version 0.20 to v4.3.0: The Ultimate Transformation

I have been working on an application that was built using an older version of material UI (V0.20). Now, I am considering upgrading to the latest version of material UI and adding new modules to the application. However, I am concerned about the potentia ...

Elevate your designs with Bootstrap Cards featuring a clickable link. Give your

I am trying to incorporate bootstrap cards into a form without using a normal link. The intention is to send the data along with other information via POST method. However, I am facing an issue with the display. The blocks should maintain the same height, ...

The JSON parser encountered an unexpected end while parsing near the section related to "jscs" and "moch"

I seem to be facing an issue with npm. I attempted to run the command npx create-react-app my-app but encountered an error. Here is the output from my command prompt: c:\Users\sysli\Desktop\reactprojects>npx create-react-app my-app ...

Using the spread syntax in the useState function

I'm facing an issue where when I use the setItemPressed function to change the value of itemid to false, it doesn't work as expected. However, if I only pass in {[itemid]: false} as an argument, it does change successfully but all other ids are r ...

When the ajax response comes in, my javascript code seems to suddenly stop

After sending a POST request, my JavaScript suddenly stops working for some unknown reason. Here's the situation: I visit my webpage, fill out the form, and then click 'Click me' : Upon clicking OK in the alert popup, I see the expected ou ...

Embed full content in iframe using bootstrap 4

Embedding an iframe of an appointment scheduling frontend on my page has been a challenge. While the width is correct, the height of the frame is too small. Despite attempting various CSS modifications, I have not been able to achieve the desired result. I ...

Struggling to retrieve a single value from my React app using sequelize findbyPk

Greetings, I am new to this and have a question that may seem silly. Despite my efforts to resolve it on my own, I have been unsuccessful. When using Postman, the data returned to "localhost:8000/playlists/1" is correct, but when I try to access it through ...

React: The 'Redirect' function is not included in the export list of 'react-router-dom'

When I try to run npm run start in the terminal, an error message appears. 'Redirect' is not exported from 'react-router-dom', causing an import error. I have attempted various solutions like reinstalling node_modules, react-router-d ...

Row within a table displaying link-like behavior

Here is the code I'm currently using: $('.table-striped tr').click( function() { var link = $(this).find('a').attr('href'); if(link != 'undefined') { window.location = link; } }).hover( func ...

How can I implement a popup overlay on a redirected URL in Next.js?

Currently in the process of developing my own URL shortener, I'm looking to incorporate a Call To Action on the target URLs page. My tech stack includes NextJs, Tailwind, NodeJs, and Express. Something along these lines: example image If anyone has ...

Setting the maximum width for images across various Bootstrap responsive sizes: a step-by-step guide

I'm struggling with optimizing images of varying sizes in bootstrap to ensure they are responsive without losing quality. Current Image: https://i.sstatic.net/akoNy.jpg Desired Image: https://i.sstatic.net/37VFX.jpg HTML: <div class="row"> ...