Skip to content

Feature: Use spread operator to pass down props. #4962

@Austio

Description

@Austio

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions