Complete the code to apply a CSS class conditionally based on the isActive state.
export default function Button() {
const [isActive, setIsActive] = React.useState(false);
return (
<button className={isActive ? [1] : 'inactive'} onClick={() => setIsActive(!isActive)}>
Click me
</button>
);
}Complete the code to add a conditional inline style that changes the text color to red when error is true.
export default function Message({ error }) {
return (
<p style={{ color: error ? [1] : 'black' }}>
{error ? 'Error occurred' : 'All good'}
</p>
);
}Fix the error in the code to conditionally add the highlight class when isSelected is true using template literals.
export default function Item({ isSelected }) {
return (
<div className={`item [1]`}>
Item content
</div>
);
}Fill both blanks to create a conditional className using the clsx library that adds 'active' when isActive is true and 'disabled' when isDisabled is true.
import clsx from 'clsx'; export default function Toggle({ isActive, isDisabled }) { return ( <button className={clsx({ [1]: isActive, [2]: isDisabled })}> Toggle </button> ); }
Fill all three blanks to create a conditional style object that sets backgroundColor to 'blue' if isPrimary is true, color to 'white' if isPrimary is true, and opacity to 0.5 if isDisabled is true.
export default function StyledBox({ isPrimary, isDisabled }) {
const style = {
backgroundColor: [1] ? 'blue' : 'transparent',
color: [2] ? 'white' : 'black',
opacity: [3] ? 0.5 : 1
};
return <div style={style}>Box</div>;
}