Created
August 14, 2019 15:40
-
-
Save chriskavanagh/62612067714f1530c4387f226a070a8f to your computer and use it in GitHub Desktop.
Using Reduce To Create Object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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