From be38b3b610078aaebb76d697fb1663000e329d45 Mon Sep 17 00:00:00 2001 From: Joel Marcey Date: Thu, 23 Jun 2016 12:30:36 -0700 Subject: [PATCH] ES6-ify Text Basics Summary: Closes https://github.com/facebook/react-native/pull/8363 Differential Revision: D3477431 Pulled By: caabernathy fbshipit-source-id: 86ee5efb84e50609fbfae82102b1dc61fea69f05 --- docs/Basics-Component-Text.md | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/docs/Basics-Component-Text.md b/docs/Basics-Component-Text.md index 28291c469c9..b2b888ef704 100644 --- a/docs/Basics-Component-Text.md +++ b/docs/Basics-Component-Text.md @@ -12,40 +12,42 @@ 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 TextBasics extends Component { + render() { + return ( + Hello World! + ); + } } // 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}`. ```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 TextBasicsWithState 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); - +AppRegistry.registerComponent('AwesomeProject', () => TextBasicsWithState); ```