My FeedDiscussionsHashnode Enterprise
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

How to return a spread operator in a map arrow function in one line

Pedro Alvarado's photo
Pedro Alvarado
·Sep 15, 2019

This doesn't work

data = data.map(item => {...item, active: false});

When returning a literal object from an arrow function construct (a lambda), you have to wrap it in parentheses so that it's seen as an expression:

data.map(item => ({...item, active: false}));