You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
reactnative/src/components/cardList/CardList.tsx

58 lines
1.2 KiB

import React, { FC, useEffect, useState } from 'react'
import { Card } from '../Card'
import { FlatList, Text, TouchableOpacity } from 'react-native'
import { useFetchWithAuth } from '../../hooks/useFetchWithAuth'
import { useNavigation } from '@react-navigation/native';
interface Props {
endpoint: string
}
export const CardList:FC <Props> = ({endpoint}) => {
const navitation = useNavigation();
let defaultData:[] = [];
const [entities, setEntities] = useState(defaultData);
const getInitData = async () => {
const { data, error } = await useFetchWithAuth(endpoint);
if (!error) {
setEntities(data);
} else {
console.log(error)
}
}
useEffect(() => {
getInitData();
}, [endpoint])
return (
<>
<FlatList
data={entities}
renderItem={({item}) =>
<Card>
<TouchableOpacity
onPress={()=>navitation.navigate("CustomerFormScreen" as never)}
>
<Text>
{item["nombre"]}
</Text>
</TouchableOpacity>
</Card>
}
keyExtractor={item => item["id"]}
/>
</>
)
}