javascript - What does spread operator outside of curly braces do? - Stack Overflow

This es from my React project, and is something I’ve never seen before:const { list, loading, failed }

This es 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.

This es 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.

Share Improve this question edited Aug 16, 2019 at 19:31 Get Off My Lawn 36.4k46 gold badges198 silver badges376 bronze badges asked Aug 16, 2019 at 19:27 TycholizTycholiz 1,2005 gold badges18 silver badges38 bronze badges 4
  • 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 poment. IMHO – Hero Qu Commented Aug 16, 2019 at 19:30
  • You are deconstructing the object into another object. – Get Off My Lawn Commented Aug 16, 2019 at 19:30
  • 1 Possible duplicate of What do these three dots in React do? – Emile Bergeron Commented Aug 16, 2019 at 19:41
  • 1 not a duplicate; my question is related to how it works when the '...' is preceded by an object – Tycholiz Commented Aug 16, 2019 at 23:45
Add a ment  | 

1 Answer 1

Reset to default 10

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} />

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745525894a4631467.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信