I'm trying to render an array of workout objects from a firestore database in react native, but I'm not getting any data showing up on my screen. There is definitely data at the location of the workouts collection and I can see the data from console.logging as well.
I'm not sure if it's an error in function logic or an error with how I'm trying to render the data.
export function TestScreen() {
const [workouts, setWorkouts] = React.useState([]);
const getWorkouts = async () => {
const workoutsCollection = collection(db, 'Users', auth.currentUser.uid, 'Workouts');
const workoutDocs = await getDocs(workoutsCollection);
workoutDocs.forEach((workout) => {
setWorkouts([...workouts, workout.data()]);
});
};
useEffect(() => {
getWorkouts();
}, []);
return (
<View>
<Text>{auth.currentUser.uid}</Text>
<Text>{auth.currentUser.phoneNumber}</Text>
{workouts &&
workouts.map((workout) => {
<Text>{workout.name}</Text>;
})}
</View>
);
}