我在 react 中有这个箭头函数:
const Welcome = ({subject, description}) => (
<div>
<Person title={`Welcome ${subject}`}></Person>
<Profile description={description}></Profile>
</div>
)
我想转换为 es5 函数,但无法让它工作:
var Welcome = function(subject,description) {
return(
<Person title="Welcome ".concat(subject)/>
<Profile description=(description)/>
);
};
我该怎么办?谢谢
最佳答案
您需要执行以下步骤:
- 用一个公共(public)父元素包裹 2 个相邻的 JSX 元素。
- 将
{ }
包裹在'Welcome'.concat(subject)
和description
周围。 - 解构函数参数。
var Welcome = function({subject, description}) {
return(
<div>
<Person title={ 'Welcome'.concat(subject) }/>
<Profile description={description}/>
</div>
);
};
关于javascript - 如何在react中将arrow函数转换为ES5函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62321237/