I need to have a className of an item based on a list of conditions. What is the best way of doing this? Right now I have an array and I push the className to the array.
const classNames = []; if (alarm?.code === 'urgent') { classNames.push(styles.yellow); } else if (alarm?.code === 'error') { classNames.push(styles.red); } else if (alarm?.code === 'disabled') { classNames.push(styles.grey); } else if (alarm?.severity === 'info') { classNames.push(styles.blue); } Then I add it to the element like this:
<div className={[...classNames]}></div> My question is mainly, what is the difference between setting the classNames like this compared to using useState and useEffect?