[英]What is the diff between this two arrow functions?
基本上,我不明白為什么第二個箭頭 function 有效,而第一個無效。
//this one doesnt
this.setState = () => {
text: e.target.value,
};
//this one works
this.setState(() => ({
text: e.target.value,
}));
第一個是賦值,第二個執行執行。
第一個將箭頭 function 分配給 this.setState 並且由於存在一個名為 setState 的現有function ,它將被您的箭頭 function 覆蓋。
第二個將箭頭 function 作為參數傳遞給 setState,setState 將調用您剛剛在其執行過程中傳遞的 function。
您可以參考文檔以更好地了解 setState 的作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.