2016-06-20 15:05:20 -07:00
---
id: basics-component-text
title: Text
layout: docs
2016-06-22 14:19:25 -07:00
category: The Basics
2016-06-20 15:05:20 -07:00
permalink: docs/basics-component-text.html
next: basics-component-image
---
The most basic component in React Native is the [`Text` ](/react-native/docs/text.html#content ) component. The `Text` component simply renders text.
This example displays the `string` `"Hello World!"` on the device.
2016-06-22 15:02:02 -07:00
```ReactNativeWebPlayer
2016-06-23 12:30:36 -07:00
import React, { Component } from 'react';
2016-06-20 15:05:20 -07:00
import { AppRegistry, Text } from 'react-native';
2016-06-23 12:30:36 -07:00
class TextBasics extends Component {
render() {
return (
< Text style = {{marginTop: 22 } } > Hello World!< / Text >
);
}
2016-06-20 15:05:20 -07:00
}
// App registration and rendering
2016-06-23 12:30:36 -07:00
AppRegistry.registerComponent('AwesomeProject', () => TextBasics);
2016-06-20 15:05:20 -07:00
```
2016-06-22 10:00:12 -07:00
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}` .
2016-06-22 15:02:02 -07:00
```ReactNativeWebPlayer
2016-06-23 12:30:36 -07:00
import React, {Component} from 'react';
2016-06-22 10:00:12 -07:00
import { AppRegistry, Text } from 'react-native';
2016-06-23 12:30:36 -07:00
class TextBasicsWithState extends Component {
constructor(props) {
super(props);
this.state = {text: "Hello World"};
}
render() {
2016-06-22 10:00:12 -07:00
var text = this.state.text;
return (
< Text style = {{marginTop: 22 } } >
{text}
< / Text >
2016-06-23 12:30:36 -07:00
)
2016-06-22 10:00:12 -07:00
}
2016-06-23 12:30:36 -07:00
}
2016-06-22 10:00:12 -07:00
// App registration and rendering
2016-06-23 12:30:36 -07:00
AppRegistry.registerComponent('AwesomeProject', () => TextBasicsWithState);
2016-06-22 15:02:02 -07:00
```