What do these three dots in React do?

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

    As you know ... are called Spread Attributes which the name represents it allows an expression to be expanded.

    var parts = ['two', 'three'];
    var numbers = ['one', ...parts, 'four', 'five']; // ["one", "two", "three", "four", "five"]
    

    And in this case(I'm gonna simplify it).

    //just assume we have an object like this:
    var person= {
        name: 'Alex',
        age: 35 
    }
    

    This:

    
    

    is equal to

    
    

    So in short, it's a neat short-cut, we can say.

提交回复
热议问题