In the next example you can see and array definite as DATA, it can be a response from your backend after axios or fetch request. You can define DATA to mock up responses in objects or arrays like do you prefer
import React, { useEffect, useState } from 'react';
import { View, Text, TextInput, StyleSheet, Dimensions, SafeAreaView, FlatList, TouchableOpacity, StatusBar } from 'react-native';
import ActionButton from 'react-native-action-button';
import Icon from 'react-native-vector-icons/FontAwesome';
import Header from '../../core/Header/Header';
import DismissKeyboard from '../../libs/DismissKeyboard';
const { width: WIDTH } = Dimensions.get('window');
import Guide from './Guide';
const styles = StyleSheet.create({
iconQr: {
fontSize: 36,
color: 'white',
},
inputContainer: {
marginTop: 10,
},
input: {
height: 45,
fontSize: 16,
paddingLeft: 45,
borderRadius: 10,
width: WIDTH - 55,
marginHorizontal: 25,
backgroundColor: '#FFFFFF',
},
container: {
flex: 1,
marginTop: StatusBar.currentHeight || 0,
},
});
const DATA = [
{
"empresa": "SHIPNOW",
"tipo_operacion": "ENTREGA",
"bultos": 1,
"sender_empresa": "SUCSHIPNOW",
"sender_remitente": "SHIPNOW",
"sender_direccion": "Av. de los Constituyentes 2985",
"sender_localidad": "CABA",
"sender_provincia": "CABA",
"sender_cp": 1428,
"comprador_apenom": "Lisandro Arguello",
"comprador_direccion": "Calle Jun\u00edn 2189",
"comprador_localidad": "Corrientes",
"comprador_provincia": "Corrientes",
"comprador_cp": 3400,
"usuario:": "shipnow",
"id:": 166308,
"zonaOrigen:": "AMBA",
"fecha_hora:": "2020-10-01 13:20:13",
"zona:": "NEA",
"confirmada:": 1,
"tipo_op:": 0,
"remito:": null,
"servicio:": "ENVIO ECOMMERCE",
"orden:": 1,
"rrId:": 61972,
"contrareembolso:": null,
"codigo_estado:": "011"
},
{ "empresa": "SHIPNOW", "tipo_operacion": "ENTREGA", "bultos": 1, "sender_empresa": "SUCSHIPNOW", "sender_remitente": "SHIPNOW", "sender_direccion": "Av. de los Constituyentes 2985", "sender_localidad": "CABA", "sender_provincia": "CABA", "sender_cp": 1428, "comprador_apenom": "Mellsa Picchio", "comprador_direccion": "Uruguay 1145", "comprador_localidad": "BBB", "comprador_provincia": "Corrientes", "comprador_cp": 3400, "usuario": "shipnow", "id": 165891, "zonaOrigen": "AMBA", "fecha_hora": "2020-09-30 07:24:41", "zona": "NEA", "confirmada": 1, "tipo_op": 0, "remito": null, "servicio": "ENVIO ECOMMERCE", "orden": 2, "rrId": 61973, "contrareembolso": null, "codigo_estado": "011" },
{ "empresa": "SHIPNOW", "tipo_operacion": "ENTREGA", "bultos": 1, "sender_empresa": "SUCSHIPNOW", "sender_remitente": "SHIPNOW", "sender_direccion": "Av. de los Constituyentes 2985", "sender_localidad": "CABA", "sender_provincia": "CABA", "sender_cp": 1428, "comprador_apenom": "Claudia Silva", "comprador_direccion": "Calle Playa Miramar 2754", "comprador_localidad": "Corrientes", "comprador_provincia": "Corrientes", "comprador_cp": 3400, "usuario": "shipnow", "id": 166152, "zonaOrigen": "AMBA", "fecha_hora": "2020-09-30 16:34:43", "zona": "NEA", "confirmada": 1, "tipo_op": 0, "remito": null, "servicio": "ENVIO ECOMMERCE", "orden": 3, "rrId": 61974, "contrareembolso": null, "codigo_estado": "011" },
{ "empresa": "SHIPNOW", "tipo_operacion": "ENTREGA", "bultos": 1, "sender_empresa": "SUCSHIPNOW", "sender_remitente": "SHIPNOW", "sender_direccion": "Av. de los Constituyentes 2985", "sender_localidad": "CABA", "sender_provincia": "CABA", "sender_cp": 1428, "comprador_apenom": "Claudia Silva", "comprador_direccion": "Azcuenga 1995", "comprador_localidad": "Corrientes", "comprador_provincia": "Corrientes", "comprador_cp": 3400, "usuario": "shipnow", "id": 166153, "zonaOrigen": "AMBA", "fecha_hora": "2020-09-30 16:34:43", "zona": "NEA", "confirmada": 1, "tipo_op": 0, "remito": null, "servicio": "ENVIO ECOMMERCE", "orden": 3, "rrId": 61974, "contrareembolso": null, "codigo_estado": "011" },
{ "empresa": "SHIPNOW", "tipo_operacion": "ENTREGA", "bultos": 1, "sender_empresa": "SUCSHIPNOW", "sender_remitente": "SHIPNOW", "sender_direccion": "Av. de los Constituyentes 2985", "sender_localidad": "CABA", "sender_provincia": "CABA", "sender_cp": 1428, "comprador_apenom": "Claudia Silva", "comprador_direccion": "Urquiza 2050", "comprador_localidad": "Corrientes", "comprador_provincia": "Corrientes", "comprador_cp": 3400, "usuario": "shipnow", "id": 166154, "zonaOrigen": "AMBA", "fecha_hora": "2020-09-30 16:34:43", "zona": "NEA", "confirmada": 1, "tipo_op": 0, "remito": null, "servicio": "ENVIO ECOMMERCE", "orden": 3, "rrId": 61974, "contrareembolso": null, "codigo_estado": "011" },
{ "empresa": "SHIPNOW", "tipo_operacion": "ENTREGA", "bultos": 1, "sender_empresa": "SUCSHIPNOW", "sender_remitente": "SHIPNOW", "sender_direccion": "Av. de los Constituyentes 2985", "sender_localidad": "CABA", "sender_provincia": "CABA", "sender_cp": 1428, "comprador_apenom": "Claudia Silva", "comprador_direccion": "Palmares Valley 50", "comprador_localidad": "Corrientes", "comprador_provincia": "Corrientes", "comprador_cp": 3400, "usuario": "shipnow", "id": 166155, "zonaOrigen": "AMBA", "fecha_hora": "2020-09-30 16:34:43", "zona": "NEA", "confirmada": 1, "tipo_op": 0, "remito": null, "servicio": "ENVIO ECOMMERCE", "orden": 3, "rrId": 61974, "contrareembolso": null, "codigo_estado": "011" },
]
function Delivieries({ navigation, route }) {
const [selectedId, setSelectedId] = useState(null);
const [guideNumber, setGuideNumber] = useState(null);
useEffect(() => route.params?.guideNumber && setGuideNumber(route.params?.guideNumber)
, [route.params?.guideNumber]);
const renderGuide = ({ item, index }) => {
console.log(item)
const backgroundColor = item.id === selectedId ? "#FFFFFF" : "#FFFFFF";
return (
<Guide
item={item}
index={index}
onPress={() => setSelectedId(item.id)}
style={{ backgroundColor }}
/>
);
};
return (
<>
<Header title="Entregas pendientes" isHome={false} />
<View style={{ marginTop: 25, marginLeft: 30, paddingBottom: 5 }}>
<Text>Ingresar número de ruta</Text>
</View>
<DismissKeyboard>
<View style={{ flex: 0.1, alignItems: 'center', justifyContent: 'center' }}>
<View style={styles.inputContainer}>
<TextInput
value={guideNumber}
onChangeText={(guideNumber) => setGuideNumber(guideNumber)}
placeholder="Número de ruta"
underlineColorAndroid="transparent"
placeholderTextColor="rgba(0,0,0,0.2)"
style={styles.input}
/>
</View>
</View>
</DismissKeyboard>
<SafeAreaView style={styles.container}>
<FlatList
data={DATA}
renderItem={renderGuide}
keyExtractor={(item) => item.id}
extraData={selectedId}
/>
</SafeAreaView>
<ActionButton
buttonColor="rgba(231,76,60,1)"
renderIcon={() => <Icon name="qrcode" style={styles.iconQr} />}
onPress={() => navigation.navigate('Scanner')}
position="center"
size={55}
/>
</>
);
};
export default Delivieries;