Make a Javascript Object with reduce()

this is how i would normally do it:

const listOfStuff = ['stuff', 'more stuff', 'amazing stuff']
let result = {}
listOfStuff.map((v, i) => {
  result[i] = v // or anything, e.g. createRef()
})

this is the same thing using reduce

const listOfStuff = ['stuff', 'more stuff', 'amazing stuff']
const result = listOfStuff.reduce((acc, value, index) => {
  acc[index] = value // or anything, e.g. createRef()
  return acc
})

the above is adapted from how (robin wieruch)[https://www.robinwieruch.de/react-intersection-observer-api/] does it with reduce(), where the id value is also used for the key in the iterated react components.

const listOfStuff = [
  { id: 'a', value: 'stuff' },
  { id: 'b', value: 'more stuff' },
  { id: 'c', value: 'amazing stuff' },
]
const result = listOfStuff.reduce((acc, value) => {
  acc[value.id] = value.value // or anything, e.g. createRef()
  return acc
})