mirror of
https://github.com/status-im/react-native.git
synced 2025-02-20 21:28:08 +00:00
Summary: Closes https://github.com/facebook/react-native/pull/8363 Differential Revision: D3477431 Pulled By: caabernathy fbshipit-source-id: 86ee5efb84e50609fbfae82102b1dc61fea69f05
1.4 KiB
1.4 KiB
id | title | layout | category | permalink | next |
---|---|---|---|---|---|
basics-component-text | Text | docs | The Basics | docs/basics-component-text.html | basics-component-image |
The most basic component in React Native is the Text
component. The Text
component simply renders text.
This example displays the string
"Hello World!"
on the device.
import React, { Component } from 'react';
import { AppRegistry, Text } from 'react-native';
class TextBasics extends Component {
render() {
return (
<Text style={{marginTop: 22}}>Hello World!</Text>
);
}
}
// App registration and rendering
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}
.
import React, {Component} from 'react';
import { AppRegistry, Text } from 'react-native';
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', () => TextBasicsWithState);