React
// Bind the class name to a fixed string
function Menu() {
return <span className="menu navigation-menu">Menu</span>;
}// Bind the class name based on a variable (prop, state ...)
function Menu({ isActive }: { isActive: boolean }) {
let className = 'menu';
if (this.props.isActive) {
className += ' menu-active';
}
return <span className={className}>Menu</span>
}import cn from 'classnames';
function Row(
{ isSelected, size }:
{ isSelected: boolean, size: string }
) {
return (
<div className={cn('row', {
selected: isSelected,
large: size === 'large',
small: size === 'small',
})}>
...
</div>
);
}// Bind the text color to a fixed color
function Menu() {
return <span style={{ color: "red" }}>Menu</span>;
}// Bind the text color based on a variable (prop, state ...)
function Menu({ isValid }: { isValid: boolean }) {
return <span style={{ color: isValid ? "green" : "red" }}>Menu</span>
}