0
const contributors = ["Here is a list of them:"];

fetch('https://api.github.com/repos/kayano-bot/kayano/contributors')
  .then(response => response.json())
  .then(data => data.forEach(user => contributors.push(user.login)))
  .then(console.log(contributors))

export const team = [
    {
        'name': 'Pukima',
        'discrim': '7331',
        'mainRole': 'Main Dev & Creator',
        'secRoles': 'Ideas, Planning, Mannager, Code, Maintain, Dependencies, Reviewer',
        'desc': 'Pukima is the Main Dev and Creator of Kayano. He had the idea behind Kayano and wanted to create Kayano because he didn\'t wanted to pay for a bot which does not even have everything he needed. So he decided to create his own bot. Later he invited bolo to join his journey and to help out.'
    },
    {
        'name': 'bolo',
        'mainRole': 'Secondary Dev',
        'desc': 'bolo is the newest addition to the Kayano team and she\'s helping out Pukima with developing the bot and eventually even the website. Not much more to say for now except: "Welcome to the team!"'
    },
    {
        'name': 'All other awesome contributors!',
        'desc': contributors.join('\u000A'),
    },
    {
        'name': 'You?',
        'mainRole': 'Marketing, Web Backend, discord.js Dev',
        'shortDesc': 'We are searching for new Members to join the team! Contact Pukima for more informations.',
    }
]

I have this code but the contributors does not get added to the desc even though it is in the Array somehow but I don't know how to access everything.

The console logged array

Array in console

What I get:

Actual content

Pukima
  • 33
  • 6
  • You're rendering (and logging) the array when it only has one element in it. **Later**, when you expand the array in the console, it has four elements, but not when you render it. You haven't shown the React code that handles doing the rendering, but if (for instance) you have that array in state, you have to create a new array; modifying the old one (as you are above) won't trigger re-rendering. – T.J. Crowder Nov 22 '21 at 15:21
  • `console.log(contributors)` is evaluated immediately, and its unspecified result seems to have been passed to `then` accidentally. If you want it to be evaluated after the side effects, what you should pass a callback that performs the `console.log` side effect in the body, i.e. something like `.then(() => console.log(contributors))` – Asad Saeeduddin Nov 22 '21 at 15:21
  • What array are you logging above? What is the value of `data` before your call `forEach()`? – mykaf Nov 22 '21 at 15:21
  • Tangentially, it can be a bit confusing in general to mix mutation and asynchronicity. One alternative might be to calculate an augmented result, instead of mutating the original. This might look something like: https://gist.github.com/c369fe9f88ade14c4da5d95e2ab520a5 (can't post multi-line snippet inline since @T.J.Crowder locked the question to point to his answer). In an `async` context, you can `await` the result and use it as you would the original mutated array. – Asad Saeeduddin Nov 22 '21 at 15:41

0 Answers0