React Native Tutorial
Core Concepts
Components and APIs
React Native Useful Resources
Selected Reading
Core Concepts
- React Native - Running Android
- React Native - Running IOS
- React Native - Router
- React Native - Debugging
- React Native - Animations
- React Native - Buttons
- React Native - HTTP
- React Native - Images
- React Native - ScrollView
- React Native - Text Input
- React Native - ListView
- React Native - Flexbox
- React Native - Styling
- React Native - Props
- React Native - State
- React Native - App
- React Native - Environment Setup
- React Native - Overview
Components and APIs
- React Native - AsyncStorage
- React Native - Geolocation
- React Native - Alert
- React Native - Text
- React Native - Switch
- React Native - Status Bar
- React Native - Picker
- React Native - ActivityIndicator
- React Native - Modal
- React Native - WebView
- React Native - View
React Native Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
React Native - ListView
React Native - ListView
In this chapter, we will show you how to create a pst in React Native. We will import List in our Home component and show it on screen.
App.js
import React from react import List from ./List.js const App = () => { return ( <List /> ) } export default App
To create a pst, we will use the map() method. This will iterate over an array of items, and render each one.
List.js
import React, { Component } from react import { Text, View, TouchableOpacity, StyleSheet } from react-native class List extends Component { state = { names: [ { id: 0, name: Ben , }, { id: 1, name: Susan , }, { id: 2, name: Robert , }, { id: 3, name: Mary , } ] } alertItemName = (item) => { alert(item.name) } render() { return ( <View> { this.state.names.map((item, index) => ( <TouchableOpacity key = {item.id} style = {styles.container} onPress = {() => this.alertItemName(item)}> <Text style = {styles.text}> {item.name} </Text> </TouchableOpacity> )) } </View> ) } } export default List const styles = StyleSheet.create ({ container: { padding: 10, marginTop: 3, backgroundColor: #d9f9b1 , apgnItems: center , }, text: { color: #4f603c } })
When we run the app, we will see the pst of names.
You can cpck on each item in the pst to trigger an alert with the name.
Advertisements