From 6f43d1f2cb05e1bd241c068581e827d6239389e3 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Mon, 25 Apr 2016 22:07:22 -0700 Subject: [PATCH] Codemod import React from 'react-native' Reviewed By: spicyj Differential Revision: D3223162 fb-gh-sync-id: 0b1af846afe17cdf8b2c2ca7f31f1197cde752c0 fbshipit-source-id: 0b1af846afe17cdf8b2c2ca7f31f1197cde752c0 --- docs/CommunicationIOS.md | 6 ++++-- docs/EmbeddedAppAndroid.md | 9 ++++++--- docs/EmbeddedAppIOS.md | 9 ++++++--- docs/JavaScriptEnvironment.md | 2 +- docs/NativeComponentsAndroid.md | 3 ++- docs/NativeComponentsIOS.md | 3 ++- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/docs/CommunicationIOS.md b/docs/CommunicationIOS.md index ebc08328d..1e1115605 100644 --- a/docs/CommunicationIOS.md +++ b/docs/CommunicationIOS.md @@ -39,7 +39,9 @@ RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge ``` 'use strict'; -import React, { +import React from 'react'; +import { + AppRegistry, View, Image } from 'react-native'; @@ -59,7 +61,7 @@ class ImageBrowserApp extends React.Component { } } -React.AppRegistry.registerComponent('ImageBrowserApp', () => ImageBrowserApp); +AppRegistry.registerComponent('ImageBrowserApp', () => ImageBrowserApp); ``` `RCTRootView` also provides a read-write property `appProperties`. After `appProperties` is set, the React Native app is re-rendered with new properties. The update is only performed when the new updated properties differ from the previous ones. diff --git a/docs/EmbeddedAppAndroid.md b/docs/EmbeddedAppAndroid.md index c459dfff4..e62a4055c 100644 --- a/docs/EmbeddedAppAndroid.md +++ b/docs/EmbeddedAppAndroid.md @@ -128,7 +128,10 @@ Copy & paste the following code to `index.android.js` in your root folder — it ```js 'use strict'; -import React, { +import React from 'react'; +import { + AppRegistry, + StyleSheet, Text, View } from 'react-native'; @@ -142,7 +145,7 @@ class MyAwesomeApp extends React.Component { ) } } -var styles = React.StyleSheet.create({ +var styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', @@ -154,7 +157,7 @@ var styles = React.StyleSheet.create({ }, }); -React.AppRegistry.registerComponent('MyAwesomeApp', () => MyAwesomeApp); +AppRegistry.registerComponent('MyAwesomeApp', () => MyAwesomeApp); ``` ## Run your app diff --git a/docs/EmbeddedAppIOS.md b/docs/EmbeddedAppIOS.md index e013ac74c..3a1b8c9b6 100644 --- a/docs/EmbeddedAppIOS.md +++ b/docs/EmbeddedAppIOS.md @@ -66,12 +66,15 @@ Copy & paste following starter code for `index.ios.js` – it’s a barebones Re ``` 'use strict'; -import React, { +import React from 'react'; +import { + AppRegistry, + StyleSheet, Text, View } from 'react-native'; -var styles = React.StyleSheet.create({ +var styles = StyleSheet.create({ container: { flex: 1, backgroundColor: 'red' @@ -88,7 +91,7 @@ class SimpleApp extends React.Component { } } -React.AppRegistry.registerComponent('SimpleApp', () => SimpleApp); +AppRegistry.registerComponent('SimpleApp', () => SimpleApp); ``` `SimpleApp` will be your **module name**, which will be used later on. diff --git a/docs/JavaScriptEnvironment.md b/docs/JavaScriptEnvironment.md index 90605fe1a..5670e79bd 100644 --- a/docs/JavaScriptEnvironment.md +++ b/docs/JavaScriptEnvironment.md @@ -37,7 +37,7 @@ ES6 * [Constants](https://babeljs.io/docs/learn-es2015/#let-const): `const answer = 42;` * [Destructuring](http://babeljs.io/docs/learn-es2015/#destructuring): `var {isActive, style} = this.props;` * [for...of](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of): `for (var num of [1, 2, 3]) {}` -* [Modules](http://babeljs.io/docs/learn-es2015/#modules): `import React, { Component } from 'react-native';` +* [Modules](http://babeljs.io/docs/learn-es2015/#modules): `import { Component } from 'react-native';` * [Computed Properties](http://babeljs.io/docs/learn-es2015/#enhanced-object-literals): `var key = 'abc'; var obj = {[key]: 10};` * Object Consise Method: `var obj = { method() { return 10; } };` * [Object Short Notation](http://babeljs.io/docs/learn-es2015/#enhanced-object-literals): `var name = 'vjeux'; var obj = { name };` diff --git a/docs/NativeComponentsAndroid.md b/docs/NativeComponentsAndroid.md index 3c32591c4..62a0cc95a 100644 --- a/docs/NativeComponentsAndroid.md +++ b/docs/NativeComponentsAndroid.md @@ -105,7 +105,8 @@ The very final step is to create the JavaScript module that defines the interfac ```js // ImageView.js -import { requireNativeComponent, PropTypes } from 'react-native'; +import { PropTypes } from 'react'; +import { requireNativeComponent } from 'react-native'; var iface = { name: 'ImageView', diff --git a/docs/NativeComponentsIOS.md b/docs/NativeComponentsIOS.md index 759d27bf0..baea312b7 100644 --- a/docs/NativeComponentsIOS.md +++ b/docs/NativeComponentsIOS.md @@ -80,7 +80,8 @@ This isn't very well documented though - in order to know what properties are av ```javascript // MapView.js -import React, { requireNativeComponent } from 'react-native'; +import React from 'react'; +import { requireNativeComponent } from 'react-native'; class MapView extends React.Component { render() {