Advertisement
Guest User

Tried to get frame for out or range index NaN

a guest
Mar 28th, 2020
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useEffect, useState } from 'react';
  2. import { Feather } from '@expo/vector-icons';
  3. import { View, FlatList, Image, Text, TouchableOpacity } from 'react-native';
  4. import { useNavigation } from '@react-navigation/native';
  5.  
  6. import logoImg from '../../assets/logo.png';
  7. import styles from './styles';
  8.  
  9. import api from '../../services/api';
  10.  
  11. export default function Incidents() {
  12.     const navigation = useNavigation();
  13.     const [incidents, setIncidents] = useState([]);
  14.  
  15.     function navigateToDetail() {
  16.         // Mesmo nome que
  17.         // <AppStack.Screen name="Details" component={Details} />
  18.         // Do arquivo routes.js
  19.         navigation.navigate('Details');
  20.     }
  21.  
  22.     async function loadIncidents() {
  23.         const response = await api.get('incidents');
  24.        
  25.         console.log('response.data');
  26.         console.log(response.data);
  27.        
  28.         setIncidents(response.data);
  29.  
  30.         console.log('incidents');
  31.         console.log(incidents);
  32.     }
  33.  
  34.     useEffect(() => {
  35.         loadIncidents();
  36.     }, [incidents]);
  37.  
  38.     return (
  39.         <View style={styles.container}>
  40.             <View style={styles.header}>
  41.                 <Image source={logoImg} />
  42.                 <Text style={styles.headerText}>
  43.                     Total de <Text style={styles.headerTextBold}>0 casos</Text>
  44.                 </Text>
  45.             </View>
  46.        
  47.  
  48.             <Text style={styles.title}>Bem-vindo!</Text>
  49.             <Text style={styles.description}>Escolha um dos casos abaixo e salve o dia</Text>
  50.  
  51.             <FlatList
  52.                 data={incidents}
  53.                 style={styles.incidentList}
  54.                 keyExtractor={incident => String(incident.id)}
  55.                 showsVerticalScrollIndicator={false}
  56.                 renderItem={({ item: incident }) => (
  57.                     <View style={styles.incidentItem}>
  58.                         <Text style={styles.incidentProperty}>ONG: {console.log(`incident: ${incident}`)}</Text>
  59.                         <Text style={styles.incidentValue}>{incident.nome}</Text>
  60.  
  61.                         <Text style={styles.incidentProperty}>CASO:</Text>
  62.                         <Text style={styles.incidentValue}>{incident.title}</Text>
  63.  
  64.                         <Text style={styles.incidentProperty}>VALOR:</Text>
  65.                         <Text style={styles.incidentValue}>{incident.value}</Text>
  66.  
  67.                         <TouchableOpacity
  68.                             style={styles.detailsButton}
  69.                             onPress={navigateToDetail}
  70.                         >
  71.                             <Text style={styles.detailsButtonText}>Ver mais detalhes</Text>
  72.                             <Feather name="arrow-right" size={16} color="#e02041" />
  73.                         </TouchableOpacity>
  74.                     </View>    
  75.                 )}
  76.             />
  77.         </View>
  78.     );
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement