Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react native list view

<FlatList data={yourData} renderIten={({item, index}) =>{
  return (
    <View key={index}>
    {item.item}
    </View>
  )
}/>
Comment

list in react native

import React, {useState} from "react";
import {
  View,
  Text,
  Button,
  TextInput,
  StyleSheet,
  FlatList,
  ScrollView,
} from "react-native";

function ListStuff(){
	const [listInput, setListInput] = useState("");
    const [listData, setListData] = useState<{
    	myKey: string;
    }>([]);
  	const [error, setError] = useState("");
  
  	const addInputDataToList = ()=>{
    	if(listInput === ""){
        	setError("input can not be empty");
          	return;
        }
      	const newListData = [...listData, {myKey: listInput}];
      	setListData(newListData);
      	setError("");
      	setListInput("");
    };
  
  	return(
    	<View style={styles.view}>
            <Text> Input </Text>
	        <TextInput value={listInput} style={styles.input} onChangeText={setListInput} />
			<Button title="add" onPress={addInputDataToList} />
              
      		<Text> List </Text>
			<ScrollView>
              <FlatList 
				style={styles.list}
				keyExtractor={item => item.myKey} 
				data={listData}
				renderItem={({item})} => (
                	<Text style={styles.item}> {item.file} </Text>
                )}
              />
			</ScrollView>
			{error && <Text>{error}</Text>}
		</View>
	);
}
export default ListStuff;

const styles = StyleSheet.create({
  input: {
    height: 40,
    width: 200,
    margin: 12,
    borderWidth: 1,
    padding: 10,
  },
  view: {
    flex: 1,
    alignItems: "center",
    justifyContent: "center",
  },
  list: {
    flex: 1,
    margin: 10,
  },
  item: {
    padding: 3,
    fontSize: 14,
    height: 22,
  },

});
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript array with random values 
Javascript :: javascript addeventlistener pass parameters 
Javascript :: .has javascript 
Javascript :: react native skeleton 
Javascript :: this in ajax call 
Javascript :: js immediately invoked function 
Javascript :: discord js check every x minutes 
Javascript :: ajax returning html instead of json 
Javascript :: what is react reveal 
Javascript :: loop into array javascript 
Javascript :: format function shift the date one day up date-fns 
Javascript :: react state 
Javascript :: longest string 
Javascript :: react table handling multiple selected checkbox 
Javascript :: sequelize migration enum 
Javascript :: multiple checkbox validation in javascript 
Javascript :: lodash isNil 
Javascript :: Stringy.JS 
Javascript :: vue v-for loop array 
Javascript :: js fadeout 
Javascript :: how to use brand icons in react 
Javascript :: nestjs prisma 
Javascript :: deploying multiple sites in firebase 
Javascript :: react native setTimeOut error 
Javascript :: web storage api 
Javascript :: js electron setup 
Javascript :: property of exception object javascript 
Javascript :: multiple images on cloudinary 
Javascript :: deploy react and express to heroku 
Javascript :: mergesort 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =