3

This comes from my React project, and is something I’ve never seen before:

const { list, loading, failed } = this.props
return <ExperienceList {…{ list, loading, failed }} />

Specifically, I’m referring to the spread operator OUTSIDE of the curly braces. I’m used to seeing them inside.

Get Off My Lawn
  • 27,770
  • 29
  • 134
  • 260
Tycholiz
  • 727
  • 1
  • 11
  • 27
  • Probably it means: 1) pick only those 3 keys from the original props and then 2) do the spreading as usual, i.e. apply those 3 props to the compoment. IMHO – Hero Qu Aug 16 '19 at 19:30
  • You are deconstructing the object into another object. – Get Off My Lawn Aug 16 '19 at 19:30
  • 1
    Possible duplicate of [What do these three dots in React do?](https://stackoverflow.com/questions/31048953/what-do-these-three-dots-in-react-do) – Emile Bergeron Aug 16 '19 at 19:41
  • not a duplicate; my question is related to how it works when the '...' is preceded by an object – Tycholiz Aug 16 '19 at 23:45

1 Answers1

9

In your example

return <ExperienceList {…{ list, loading, failed }} />

is equivalent to

return <ExperienceList {…this.props} />

it does the same thing, which is

return <ExperienceList list={list} loading={loading} failed={failed} />
Federkun
  • 30,933
  • 8
  • 62
  • 80