orberkov orberkov - 3 months ago 12
Javascript Question

What Is The Meaning Of This react-native syntax: const equals React

I was going through a React Native course on

pluralsight.com
when I encountered the following syntax:

Import React from 'react-native';
const {
Text,
View
} = React;


The syntax here is unclear to me. Can you explain what
const
following
{}
and
= React
mean?

Answer

This is ECMAScript 6 destructuring: (https://developer.mozilla.org/it/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment)

var data = { foo: "SOME VAULE", baz: "OTHER VALUE" };

var {foo, baz} = data;

console.log(foo, " AND ",  baz);

Comments