What do these three dots in React do?

前端 未结 29 3334
不思量自难忘°
不思量自难忘° 2020-11-21 23:53

What does the ... do in this React (using JSX) code and what is it called?



        
29条回答
  •  我在风中等你
    2020-11-22 00:36

    The three dots (...) are called the spread operator, and this is conceptually similar to the ES6 array spread operator, JSX taking advantage of these supported and developing standards in order to provide a cleaner syntax in JSX

    Spread properties in object initializers copies own enumerable properties from a provided object onto the newly created object.

    let n = { x, y, ...z };
    n; // { x: 1, y: 2, a: 3, b: 4 }
    

    Reference:

    1) https://github.com/sebmarkbage/ecmascript-rest-spread#spread-properties

    2) https://facebook.github.io/react/docs/jsx-spread.html

提交回复
热议问题