-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Description
Hello,
I propose adding a feature that allows the use of ES6 spread operator to destructure an object into props passed into a component. This feature idea comes from the use of it in react, which is documented here. https://facebook.github.io/react/docs/jsx-in-depth.html#spread-attributes
Imagine an ActorCard that displays a users firstName, lastName, email and imageUrl picture.
Currently
<ActorCard
:firstName="currentUser.firstName"
:lastName="currentUser.lastName"
:email="currentUser.email"
:imageUrl="currentUser.imageUrl"
>
</ActorCard>
//or by passing object
<ActorCard :user="currentUser"></ActorCard>
Using spread would allow to pass flat props to the component without all the boiler plate of manually specifying each prop.
<ActorCard {{...currentUser}}></ActorCard>
would compile into the first example above
Doing this way encourages keeping props flat, which ultimately makes components more reusable (i.e. i don't have to construct an object that has property of firstName and lastName just to reuse this actor card if i go the easy route and just pass in a user.)
If this is something that is agreeable, i'm happy and willing to put in the work to get a PR for it.
Thanks!
Austin