What do these three dots in React do?

前端 未结 29 2664
不思量自难忘°
不思量自难忘° 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:19

    This will be compiled into:

    React.createElement(Modal, { ...this.props, title: "Modal heading", animation: false }, child0, child1, child2, ...)
    

    where it gives more two properties title & animation beyond the props the host element has.

    ... is the ES6 operator called Spread.

    See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax

提交回复
热议问题