Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES6-ify Text Basics #8363

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions docs/Basics-Component-Text.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Text style={{marginTop: 22}}>Hello World!</Text>
);
class TextBasics extends Component {
render() {
return (
<Text style={{marginTop: 22}}>Hello World!</Text>
);
}
}

// 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 style={{marginTop: 22}}>
{text}
</Text>
);
)
}
});
}

// App registration and rendering
AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);

AppRegistry.registerComponent('AwesomeProject', () => TextBasicsWithState);
```