From 19a6fa0c705d175a7e31415c1a325dbff80239cf Mon Sep 17 00:00:00 2001 From: Joel Marcey Date: Thu, 23 Jun 2016 08:49:26 -0700 Subject: [PATCH 1/3] ES6-ify Text Basics --- docs/Basics-Component-Text.md | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/docs/Basics-Component-Text.md b/docs/Basics-Component-Text.md index 28291c469c94a6..7d30fd88b3cad4 100644 --- a/docs/Basics-Component-Text.md +++ b/docs/Basics-Component-Text.md @@ -12,13 +12,15 @@ The most basic component in React Native is the [`Text`](/react-native/docs/text This example displays the `string` `"Hello World!"` on the device. ```ReactNativeWebPlayer -import React from 'react'; +import React, {Component} from 'react'; import { AppRegistry, Text } from 'react-native'; -const AwesomeProject = () => { - return ( - Hello World! - ); +class AwesomeProject extends Component { + render() { + return ( + Hello World! + ); + } } // App registration and rendering @@ -28,24 +30,24 @@ AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject); In this slightly more advanced example we will display the `string` `"Hello World"` retrieved from this.state on the device and stored in the `text` variable. The value of the `text` variable is rendered by using `{text}`. ```ReactNativeWebPlayer -import React from 'react'; +import React, {Component} from 'react'; import { AppRegistry, Text } from 'react-native'; -var AwesomeProject = React.createClass({ - getInitialState: function() { - return {text: "Hello World"}; - }, - render: function() { +class AwesomeProject extends Component { + constructor(props) { + super(props); + this.state = {text: "Hello World"}; + } + render() { var text = this.state.text; return ( {text} - ); + ) } -}); +} // App registration and rendering AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject); - ``` From 4f14546f1cf077608aa00c8f8e8bbc8cafd5c51e Mon Sep 17 00:00:00 2001 From: Joel Marcey Date: Thu, 23 Jun 2016 09:17:27 -0700 Subject: [PATCH 2/3] Make the class names a little more meaningful --- docs/Basics-Component-Text.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/Basics-Component-Text.md b/docs/Basics-Component-Text.md index 7d30fd88b3cad4..3bf6292f050672 100644 --- a/docs/Basics-Component-Text.md +++ b/docs/Basics-Component-Text.md @@ -15,7 +15,7 @@ This example displays the `string` `"Hello World!"` on the device. import React, {Component} from 'react'; import { AppRegistry, Text } from 'react-native'; -class AwesomeProject extends Component { +class TextBasics extends Component { render() { return ( Hello World! @@ -24,7 +24,7 @@ class AwesomeProject extends Component { } // App registration and rendering -AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject); +AppRegistry.registerComponent('AwesomeProject', () => TextBasics); ``` In this slightly more advanced example we will display the `string` `"Hello World"` retrieved from this.state on the device and stored in the `text` variable. The value of the `text` variable is rendered by using `{text}`. @@ -33,7 +33,7 @@ In this slightly more advanced example we will display the `string` `"Hello Worl import React, {Component} from 'react'; import { AppRegistry, Text } from 'react-native'; -class AwesomeProject extends Component { +class TextBasicsWithState extends Component { constructor(props) { super(props); this.state = {text: "Hello World"}; @@ -49,5 +49,5 @@ class AwesomeProject extends Component { } // App registration and rendering -AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject); +AppRegistry.registerComponent('AwesomeProject', () => TextBasicsWithState); ``` From 2f74432f05201f2e9a3778c14d9676d35efe8874 Mon Sep 17 00:00:00 2001 From: Joel Marcey Date: Thu, 23 Jun 2016 11:29:44 -0700 Subject: [PATCH 3/3] Spaces around Component --- docs/Basics-Component-Text.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Basics-Component-Text.md b/docs/Basics-Component-Text.md index 3bf6292f050672..b2b888ef704194 100644 --- a/docs/Basics-Component-Text.md +++ b/docs/Basics-Component-Text.md @@ -12,7 +12,7 @@ The most basic component in React Native is the [`Text`](/react-native/docs/text This example displays the `string` `"Hello World!"` on the device. ```ReactNativeWebPlayer -import React, {Component} from 'react'; +import React, { Component } from 'react'; import { AppRegistry, Text } from 'react-native'; class TextBasics extends Component {