I noticed the following in a React app:
<UserList
{...{ userIdsTyping, users }}
/>
What exactly is {...{ userIdsTyping, users }} doing here? I understand it's passing children to the UserList component, but how does the spread operator work here? What interaction does it have with userIdsTyping and users?
The spread operator "expands" the object inline. It's equivalent to the following syntax:
<UserList
userIdsTyping={userIdsTyping}
users={users}
/>
The object itself { userIdsTyping, users } is ES6 shorthand, and expands to {userIdsTyping: userIdsTyping, users: users}.
This assumes values for userIdsTyping and users are defined somewhere else within scope.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With