[英]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.