Css properties as falsie values in react

46 Views Asked by At

I'm looking for the answer to the question how should I use conditional styles with conditional operators.

What code example would be the best? Can we use non css values?

margin: isOpen ? '10px' : undefined
margin: isOpen ? '10px' : 'initial'

enter image description here

Is it okay to use it in that way? (so we pass 'undefined' and 'null' as a css property)

margin: isOpen ?? '10px'

and one more (so we pass every falsie value)

margin: isOpen && '10px'

or maybe this

margin: isOpen ? '10px' : ''

As context we can say we wanna use it in react style porp, or in styled-components

0

There are 0 best solutions below