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

后端 未结 4 1224
日久生厌
日久生厌 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:31

    If you don't need to mutate the array and just do the console.log() you can do data.forEach() instead. It shouldn't give you the warning. Map expects you to return a value after you've transformed the array.

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

提交回复
热议问题