【发布时间】:2017-09-15 01:43:10
【问题描述】:
我需要根据传入我的 react 组件的 prop 设置 div 的背景颜色。 React 组件的内联样式我很清楚,但我不知道如何正确应用内联样式以根据道具进行更改。如果道具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>
);
}
【问题讨论】:
标签: css reactjs conditional