Expected to return a value in arrow; function array-callback-return. Why?

后端 未结 4 1179
日久生厌
日久生厌 2021-01-07 17:59

I\'m having some issues understanding why I\'m getting a compile warning on this piece of my react code

fetch(\'/users\')
        .then(res => res.json())         


        
4条回答
  •  醉梦人生
    2021-01-07 18:23

    From MDN:

    The map() method creates a new array with the results of calling a provided function on every element in the calling array.

    That means the map method has to be returned. So,you should change your code like this:

    fetch('/users')
        .then(res => res.json())
        .then(data => {
            data.map(users => {
                return console.log(users);
            });
        });
    

    or use forEach() instead of map()

提交回复
热议问题