[英]no-return-assign - when to disable
我正在嘗試在此對象數組中傳遞ID:
const children = [{name: Jack, age: 8}, {name: Joe, age: 6}];
children.forEach((child) => (child.id = v4()));
我不斷收到eslint error no-return-assign
這確實讓我煩惱(雙關語)
我試過了:
children.forEach(child => child.id = v4());
children.forEach((child) => (child.id = v4()));
children.forEach(child => (child.id = v4()));
children.forEach((child) => {
return child.id = v4()
});
沒有工作。
我應該禁用eslint嗎? 有解決方法嗎?
好吧,不要從回調函數返回任何東西。 寫吧
children.forEach(child => {
child.id = v4();
});
甚至更簡單
for (const child of children) {
child.id = v4();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.