Reputation: 10975
What does this code actually mean?
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
Image,
View,
} = React;
I know the React
is a module imported by node, Does it copy the React
object to the list above?
And I added the
var {Image} = React;
it works too. I'm new to Node.js and React and get confused.
[SOLVED] by Ramanlfc: This is a destructing assignment:
The destructuring assignment syntax is a JavaScript expression that makes it possible to extract data from arrays or objects using a syntax that mirrors the construction of array and object literals.
Upvotes: 2
Views: 137
Reputation: 20633
As mentioned by Ramanlfc in the comments; it is the ECMAScript 2015 Destructuring assignment syntax.
Essentially that statement
var {
AppRegistry,
StyleSheet,
Text,
Image,
View,
} = React;
is the equivalent of
var AppRegistry = React.AppRegistry,
StyleSheet = React.StyleSheet,
Text = React.Text,
Image = React.Image,
View = React.View;
It's an easier way of assigning object properties to variables of the same name;
Upvotes: 4