Skip to content

Instantly share code, notes, and snippets.

@chriskavanagh
Created August 14, 2019 15:40
Show Gist options
  • Save chriskavanagh/62612067714f1530c4387f226a070a8f to your computer and use it in GitHub Desktop.
Save chriskavanagh/62612067714f1530c4387f226a070a8f to your computer and use it in GitHub Desktop.
Using Reduce To Create Object
Add refs to each element in list using reduce, by creating obj.
list = [
{
id: "a",
firstname: "Robin",
lastname: "Wieruch",
year: 1988
},
{
id: "b",
firstname: "Dave",
lastname: "Davidds",
year: 1990
}
];
const refs = list.reduce((acc, value) => {
acc[value.id] = createRef();
return acc;
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment