在使用 AND 运算符计算第 6 行中的表达式时,
1. export default function App() {
2. var isDone = false;
3. const strikethrough = { textDecoration: "line-through" };
4. return (
5. <div className="App">
6. <h1 style={isDone && strikethrough}>Hello CodeSandbox</h1>
7. </div>
8. );
9. }
什么时候isDone = false,我收到一个错误
'
styleprop 需要从样式属性到值的映射,而不是字符串。例如,使用 JSX 时,style={{marginRight:spacing + 'em'}}。
当isDone = true,一切正常。
不知何故,null 不起作用,为了检查这一点,我使用了以下内容
<h1 style={}>Hello CodeSandbox</h1>
这给出了一个错误,即“JSX 属性只能被分配一个非空表达式”
我正在从在线课程中学习 ReactJs。这里发生了什么事?