[英]How to convert arrow Function to ES5 function in react
I have this arrow function in react:我有这个箭头 function 反应:
const Welcome = ({subject, description}) => (
<div>
<Person title={`Welcome ${subject}`}></Person>
<Profile description={description}></Profile>
</div>
)
and I would like to convert to an es5 function but I am not able to get it to work:我想转换为 es5 function 但我无法让它工作:
var Welcome = function(subject,description) {
return(
<Person title="Welcome ".concat(subject)/>
<Profile description=(description)/>
);
};
How should I go about it?我应该怎么go一下呢? Thanks
谢谢
You need to do following steps:您需要执行以下步骤:
{ }
around 'Welcome'.concat(subject)
and description
.{ }
包裹在'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>
);
};
try this bro试试这个兄弟
You forgot the destructuring in the params and also fogot to wrap the the html content under one parent tag您忘记了参数中的解构,也忘记了将 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.