Home > Article > Web Front-end > Getting Started with React Native
Most people who are new to react native are deeply confused about this, so I will once again share an introductory article about react native
1: Props (property)
Most components can be customized using various parameters when they are created. These parameters used for customization are called props (properties). props are specified in the parent component, and once specified, they will not change during the life cycle of the specified component
Customized by using different properties in different scenarios , you can maximize the reuse scope of custom components. Just reference this.props in the render function and handle it as needed. Here is an example:
2: State (state)
We use two kinds of data to control a component:props and state. Props are specified in the parent component, and once specified, they will not change during the life cycle of the specified component. For data that needs to be changed, we need to use state.
Generally speaking, you need to initialize thestate in the constructor (Annotation: This is how ES6 is written, Many early ES5 examples used the getInitialState method to initialize the state, which will gradually be eliminated), and then call the setState method when modifications are needed.
Suppose we need to create a text that keeps flashing. The text content itself has been specified when the component is created, so the text content should be aprop. The display or hidden state of text (fast switching between display and concealment produces a flickering effect) changes over time, so this state should be written in state.
The above is the detailed content of Getting Started with React Native. For more information, please follow other related articles on the PHP Chinese website!