React Native Props & State

Source: Internet
Author: User

Today I knocked at the slightest bit of code and looked at the usage of props and state.

Originally thought that State is just a status, but read the original text, only to know that state is a set of state, these states are defined by the developers themselves, are unified under the big class of States, like props is

This.props.propertyName

This.state.stateName

In this form, props and state are two types of control components, props is a developer-defined component parameter, which states a status that is used to control the contents of the component

/**
* Sample React Native App
* Https://github.com/facebook/react-native
* @flow
*/

Import React, {Component} from ' React ';

Import {
Appregistry,
StyleSheet,
Text,
View,
Image,
} from ' React-native '

Class Blink extends component{

Constructor (props) {
Super (props);
This.state = {Showtext:true,showredcolor:false};

Toggle the state every second
SetInterval (() = {
This.setstate ({showtext:!this.state.showtext, Showredcolor:!this.state.showredcolor});
}, 1000);
}

Render () {
Let display = This.state.showText? This.props.text: ";
display = This.state.showRedColor? "Red color text":d isplay
Return (
<Text> {display}</text>
);
}
}

class Blinkapp extends component{
render () {
Return (
<View>
<blink text= ' I love to Blink '/>
<blink text= ' Yes blinking are so great '/>
<blink text= ' Why does they ever take this out of HTML '/>
<blink text= ' look at me look at me look at me '/>
<redtextview rdname= ' This is a text '/>
<redtextview rdname= ' has not set color yet. ' />
<redtextview rdname= ' End '/>
<bluetextview blname= ' Blue name begin '/>
<bluetextview blname= ' have not set color yet '/>
<bluetextview blname= ' Blue name end '/>
</View>
)
}
}

Class Redtextview extends component{

Render () {
Return (
<View>
<Text>{this.props.rdName}</Text>
</View>
)
}
}

Class Bluetextview extends component{

Render () {
Return (
<View>
<Text>{this.props.blName}</Text>
</View>
)
}
}

Appregistry.registercomponent (' HelloWorld ', () = Blinkapp);



React Native Props & State

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.