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

I am trying to use dynamic data to change and trigger classnames but it always only result to true despite data containing false. Any solution?

I am trying to dynamically change the styles based on ternary classnames.
I am trying to change the background to dark or light based on the input on the workWrapper in here:
I have a Data.js wherein I can just put every data in one file

Which is connected to this component

and I am basing it to here

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

However, I cannot figure out why the dark classname is not being triggered when I already set the workWrapper value to false/true, it is still light

The CSS:

.normColor{
  background-color: #f3f3f3;
  width: 100%;
  height: 100vh;
  margin: 0 auto;
}

.normColor .dark{
  background-color: #232A4E;
  width: 100%;
  height: 100vh;
  margin: 0 auto;
}

I already tried messing around with the component, searching for other similar issues to mine and trying to search youtube videos regarding it but I cannot find any solution.

>Solution :

You forget to de-structure your props.

try this :-

const WorkSection = ({workWrapper}) =>{
    return(<div className={workWrapper?'normColor':'dark'}></div>)
}

And you checking props, if it is null or not. And it will always give you true, because components always have props

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