Inheriting an Object

When creating a new object that inherits another object we can use the Spread syntax to inherit the parent object.

object1:{
a: 10,
b: 20
};

object2:{
...object1,
c: 14
};

What do these three dots (…) in React do ?

In React the three dots (…) notation is used as the Spread syntax and Rest parameter that has been part of React for a long time when it could be used via transpilation, although, it has been made a part of JavaScript as part of the ES2015 syntax.

The Spread syntax is used to deconstruct an array or object into separate variables where the exact number of elements in the array may not be known or when we wish to keep an attribute or a set of attributes separate from the entire object.

Three dots (…) can be used as follows:

Table of Content

  • Passing attributes
  • Inheriting an Object:
  • Concatenate Arrays
  • Destructuring Arrays

Similar Reads

Method 1: Passing attributes

An object can directly be passed to a component instead of passing each data value in the object separately....

Method 2: Inheriting an Object:

When creating a new object that inherits another object we can use the Spread syntax to inherit the parent object....

Method 3: Concatenate Arrays

We can also concatenate arrays using the Spread syntax as follows....

Method 4: Destructuring Arrays

Destructuring an array into separate components can also be performed using the Spread Syntax....

Contact Us