0

I'm newbie to react native. Recently I've seen some tutorials about it. There is something vague for me.

Sometimes react will be added to the project like this:

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';

And sometimes else it will be done like this:

var React = require('react-native');

Are these equivalent? If not, when exactly should I use which one?

stack
  • 10,280
  • 19
  • 65
  • 117
  • import are ES6 based while require is is a common node require syntax, Its just an way of importing libraries – Vinod Louis Apr 12 '17 at 06:03
  • It has nothing to do with react. They do the same, at the very top level, but Imports were added in ES6, since it supports native modules. There are more technical differences, like import can be asynchronous – Giorgi Khorguani Apr 12 '17 at 06:03
  • Possible duplicate of [Using Node.js require vs. ES6 import/export](https://stackoverflow.com/questions/31354559/using-node-js-require-vs-es6-import-export) – Paul Sweatte Jul 03 '17 at 20:23

0 Answers0