What do these three dots in React do?

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

    ... this syntax is part of ES6 and not something which you can use only in React.It can be used in two different ways; as a spread operator OR as a rest parameter.You can find more from this article: https://www.techiediaries.com/react-spread-operator-props-setstate/

    what you have mentioned in the question is something like this, let's assume like this,

        function HelloUser() {
          return ;
        }
    

    with the use of spread operator you can pass props to the component like this.

         function HelloUser() {
           const props = {Name: 'ABC', City: 'XYZ'};
           return ;
         }
    

提交回复
热议问题