Use of Colon in object assignment destructuring Javascript

Shorn Jacob

Working with React.js and React Router

import React, { Component } from 'react';

const PrivateRoute = ({ component: Component, ...rest }) => (
  <Route {...rest} render={} />
)

*{ component: Component, ...rest }*

..rest is the use of spread syntax but what does *component: Component* do

Suman Kundu

In ES6 this will assign the value to a new variable in this case named foo

let obj = {
  name: 'Some Name',
  age: '42',
  gender: 'coder'
};
let { name: foo, ...rest } = obj;
console.log({foo, rest}) // { foo: 'Some Name', rest: { age: 42, gender: 'coder' } }
//

In this case, name will not be defined

See assigning to new variable names

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Selective object destructuring with assignment in JavaScript?

Javascript object destructuring with assignment in Babel

How to use a destructuring assignment inside an object

Object property assignment with destructuring?

Destructuring assignment in object creation

JavaScript Destructuring Assignment

How can I use this in the left side of the object destructuring assignment?

Destructuring Assignment to Pass an Object as a Function's Parameters in Javascript behaviour

How does dependent object destructuring assignment work in JavaScript?

Nested in object array destructuring with assignment

Must use destructuring props assignment

Is the order of destructuring assignment in JavaScript guaranteed?

Must use destructuring props assignment (react/destructuring-assignment)

Must use destructuring theme assignment react/destructuring-assignment

What's the difference between object destructuring and normal object assignment in Javascript ES6?

Javascript Replacement With Object Destructuring

JavaScript object destructuring and aliasing

javascript: object destructuring

Problems with JavaScript object destructuring

How to use ES6 destructuring assignment to assign one object to another

Partial object copying using Destructuring Assignment

destructuring assignment of array stored in object property

Destructuring assignment to costruct a new object - Is it possible?

Destructuring assignment - object properties to variables in C#

Destructuring assignment in function call while preserving the object

Object destructuring assignment with default value of itself

Array destructuring into object assignment in a single instruction

Object Destructuring Assignment Behaving Weirdly in Constructor

Dynamic JavaScript object with colon