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

Css module in ReactJS, using in ternary operators syntax

I have a useState and try to render my Modal windows based on it.
Here is my code and I used css modules for my classes.
The thing is I am not able to find the correct syntax to doing so.
I ended up writing this but it does not work.

export default function Modal({ content }) {
  const [showModal, setShowModal] = useState(true);

  return (
    <div className={`${showModal} ? ${styles.ModalWindow} : ${styles.DisplayNone}`} </div>

>Solution :

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

The backtick (`) symbol indicates a template literal/string in JavaScript. You would only want to use this feature if you want the class to literally be something like "condition ? window-class : hidden".

In this case, you want the expression to be evaluated, not converted into a string literal. So just get rid of those template literal markers:

<div className={showModal ? styles.ModalWindow : styles.DisplayNone} </div>
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