1

I am just starting to learn React Native and I'm a bit confused. The docs say to use:

'use strict'; 
var React = require('react'); 
var ReactNative =   require('react-native'); 
var { StyleSheet, TabBarIOS, Text, View, } = ReactNative;

However when I run:

react-native init MyApp

I get this code:

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

Can someone please explain the difference and which one I should be using. When I try to create a component with the 'strict' I get this error:

Seems you're trying to access 'ReactNative.Component' from the 'react-native' package. Perhaps you meant to access 'React.Component' from the 'react' package instead?

So why do all the docs say to use the first method ? I'm really confused on this.

bstras21
  • 981
  • 3
  • 11
  • 32
  • Which docs are you looking at? This is the 'hello world' example which uses import statements https://facebook.github.io/react-native/docs/tutorial.html#content – azium Sep 26 '16 at 17:00
  • ah yea, I see some pages now that have the first way. I would definitely go with the second way as I'm sure you'll see more and more examples migrate that way. also, as confusing as it may be, they're pretty similar so don't get caught up in knowing exactly which syntax as to use. as it stands there are many different ways to do things in javascript, but the newer stuff is for the most part easier to use / learn – azium Sep 26 '16 at 17:02
  • @bstras21 Please add links to the part of the docs you're referring to. As the error you received states, `React.Component` is not a part of the React Native package anymore. This was changed in RN v.0.25, please see the [changelog](https://github.com/facebook/react-native/releases/tag/v0.26.0). – NiFi Sep 26 '16 at 20:00
  • Possible duplicate of [Does React Native use require or import?](http://stackoverflow.com/questions/37266515/does-react-native-use-require-or-import) – aris Oct 17 '16 at 23:07

0 Answers0