[英]How to convert arrow Function to ES5 function in react
我有这个箭头 function 反应:
const Welcome = ({subject, description}) => (
<div>
<Person title={`Welcome ${subject}`}></Person>
<Profile description={description}></Profile>
</div>
)
我想转换为 es5 function 但我无法让它工作:
var Welcome = function(subject,description) {
return(
<Person title="Welcome ".concat(subject)/>
<Profile description=(description)/>
);
};
我应该怎么go一下呢? 谢谢
您需要执行以下步骤:
{ }
包裹在'Welcome'.concat(subject)
和description
周围。var Welcome = function({subject, description}) {
return(
<div>
<Person title={ 'Welcome'.concat(subject) }/>
<Profile description={description}/>
</div>
);
};
var Welcome = function(subject,description) {
return(
<div>
<Person title={"Welcome ".concat(subject)}/>
<Profile description={description}/>
</div>
);
};
试试这个兄弟
您忘记了参数中的解构,也忘记了将 html 内容包装在一个父标签下
var Welcome = function({subject,description}) {
return(
<div>
<Person title="Welcome ".concat(subject)/>
<Profile description=(description)/>
</div>
);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.