-
I have the following code which controls visibility of an element based on a const styles = stylex.create({
base: (visible: boolean) => ({
display: {
default: visible ? 'flex' : 'none',
[md]: 'flex',
},
}),
});
// ... within the compoenent
const [visible, setVisible] = useState<boolean>(false);
<div {...stylex.props(styles.base(visible))}>
// ...
</div> Is there something wrong in using the operator |
Beta Was this translation helpful? Give feedback.
Answered by
nmn
Jan 2, 2024
Replies: 1 comment 5 replies
-
While some logic is allowed within dynamic styles and it's an issue of our ESLint rule not being smart enough, you should never use dynamic styles for such cases. Do this instead: const styles = stylex.create({
base: {
display: {
default: 'none',
[md]: 'flex',
},
},
visible: {
display: 'flex',
}
});
// ... within the compoenent
const [visible, setVisible] = useState<boolean>(false);
<div {...stylex.props(styles.base, visible && styles.visible)}>
// ...
</div> |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
nmn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While some logic is allowed within dynamic styles and it's an issue of our ESLint rule not being smart enough, you should never use dynamic styles for such cases. Do this instead: