我需要根据传入我的反应组件的道具来设置div的背景颜色。 React组件的内联样式我非常清楚,但我不知道如何正确应用内联样式以根据prop来更改。如果道具selected
等于true
,我只想在right-toggle
的联机样式中分配道具rightSideColor
的值。条件内联样式基于道具的反应组件
export default function UiToggle(props) {
const { leftLabel, rightLabel, selected, rightSideColor, leftSideColor } = props;
return (
<div className="lr-toggle-select" style={{ width: `${width}px` }} >
<div className="lr-gray-background" />
<div>
{leftLabel}
</div>
<div className={'lr-toggle right-toggle' style={{ selected ? (backgroundColor: rightSideColor) : null }}>
{rightLabel}
</div>
</div>
);
}