【发布时间】:2021-07-29 23:27:46
【问题描述】:
我认为我对箭头函数的编码问题存在误解。我下面的代码应该将返回的 jsx 存储在变量“header”中。但它不起作用。是不是我传入的参数不正确?
switch (props.category) {
case 'White':
heading = 'White Advantages';
break;
case 'Black':
heading = 'Black Advantages';
break;
case 'Neutral':
heading = 'Neutral';
break;
default:
break;
}
let header = (heading, advisorTags) => {
if (advisorTags.length > 0) {
return (
<Typography variant="h6" component="h6" style={{ fontSize: 16 }}>
{heading}
</Typography>
);
}
};
【问题讨论】:
-
标头是反应组件吗? switch 语句是如何出现的?
-
header 只是一个变量。你可以看到我让 header = ... switch 语句设置变量“heading”,然后我在 header 函数的参数中使用它。
标签: reactjs