0

i want to fix this problem

i tried every thing :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
        }
       );
      });
     });
    });

Line 31: Expected to return a value in arrow function array-callback-return
Line 32: Expected to return a value in arrow function array-callback-return
Line 40: Expected to return a value in arrow function array-callback-return
Line 41: Expected to return a value in arrow function array-callback-return

Search for the keywords to learn more about each warning. To ignore, add // eslint-disable-next-line to the line before.

2 Answers2

1

If you're trying to loop through an array functionally, use .forEach instead of .map.

.map is supposed to be used when you want to create a new array from the values of an existing array.

See this answer for more information: 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
    }
   );
  });
 });
});
btomw
  • 2,512
  • 2
  • 20
  • 25
1

Just replace your maps with forEach. Map is supposed to return something.

Kamlesh Tajpuri
  • 482
  • 3
  • 11