如何在 JSX React 中结合内联样式和外部导入常量样式
How to combine inline style and external import const style in JSX React
例如我想做这样的事情:
const style = {
color: 'red'
}
<div style={style + { width: '10%' }}>Hello</div>
在 JSX 中结合常量样式和内联样式。
您想使用 spread syntax (...
) 组合对象。
const style = {
color: 'red'
};
<div
style={{
// Spread out previous `style` properties
...style,
width: "10%",
}}
>
Hello
</div>
例如我想做这样的事情:
const style = {
color: 'red'
}
<div style={style + { width: '10%' }}>Hello</div>
在 JSX 中结合常量样式和内联样式。
您想使用 spread syntax (...
) 组合对象。
const style = {
color: 'red'
};
<div
style={{
// Spread out previous `style` properties
...style,
width: "10%",
}}
>
Hello
</div>