【发布时间】:2020-06-14 21:02:03
【问题描述】:
我从 React 文档中发现了以下代码:
import {ThemeContext} from './theme-context';
class ThemedButton extends React.Component {
render() {
let props = this.props;
let theme = this.context;
return (
<button
{...props}
style={{backgroundColor: theme.background}}
/>
);
}
}
ThemedButton.contextType = ThemeContext;
export default ThemedButton;
为什么样式有双花括号而不是只有一个?:
style={{backgroundColor: theme.background}}
【问题讨论】:
-
因为您正在创建一个带有字段
backgroundColor... 或任何其他有效字段的React.CSSProperties对象。
标签: reactjs