![](/img/trans.png)
[英]Expected to return a value at the end of arrow function on reactjs how to fix this error?
[英]How to fix this "expected to return a value in arrow function" error
我想解決這個問題
我嘗試了每件事:p
Tabs.map(tab => {
Lessons.filter(lesson => lesson.section_id === undefined && lesson.tab_id === tab.id).map(lesson => {
this.state.items.push(
{
id: lesson.id,
slug: lesson.slug
}
);
});
Sections.filter(section => section.tab_id === tab.id).map(section => {
Lessons.filter(lesson => lesson.section_id === section.id).map(lesson => {
this.state.items.push(
{
id: lesson.id,
slug: lesson.slug
}
);
});
});
});
第 31 行:預期在箭頭函數 array-callback-return 中返回一個值
第 32 行:預期在箭頭函數 array-callback-return 中返回一個值
第 40 行:預期在箭頭函數 array-callback-return 中返回一個值
第 41 行:預期在箭頭函數 array-callback-return 中返回一個值
搜索關鍵字以了解有關每個警告的更多信息。 要忽略,請將 // eslint-disable-next-line 添加到前一行。
如果您嘗試在功能上遍歷數組,請使用.forEach
而不是.map
。
當您想從現有數組的值創建新數組時,應該使用.map
。
有關更多信息,請參閱此答案: https : //stackoverflow.com/a/34426481/1337057
Tabs.forEach(tab => {
Lessons.filter(lesson => lesson.section_id === undefined && lesson.tab_id === tab.id).forEach(lesson => {
this.state.items.push(
{
id: lesson.id,
slug: lesson.slug
}
);
});
Sections.filter(section => section.tab_id === tab.id).forEach(section => {
Lessons.filter(lesson => lesson.section_id === section.id).forEach(lesson => {
this.state.items.push(
{
id: lesson.id,
slug: lesson.slug
}
);
});
});
});
只需將您的地圖替換為 forEach。 Map 應該返回一些東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.