Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

263
Views
How do I print out my object array in React Native Expo?

How do I print out the values I see in my console? I need to display them in the app I am running in React Native using Expo. Do I need to map through the object array and print out values, or run the MyProfile a different way because it is asynced?

Thanks!

import { useNavigation } from "@react-navigation/core";
import React, { useEffect, useState } from "react";
import firebase from "firebase/app";
import "firebase/firestore";
import { auth } from "../firebase";
import {
  Text,
  View,
  StyleSheet,
  Image,
  SafeAreaView,
  ScrollView,
  TouchableOpacity,
} from "react-native";
import { Animate } from "react-native-entrance-animation";
import Copyright from "./Copyright";

const ProfileScreen = () => {
  const navigation = useNavigation();

  const MyProfile = () => {
    const [posts, setPosts] = useState(null);
    let myPosts = "Profile loading...";

    const collectIdsAndDocs = (doc) => {
      return { id: doc.id, ...doc.data() };
    };

    useEffect(() => {
      const getPost = async () => {
        const snapshot = await firebase
          .firestore()
          .collection("profiles")
          .where("email", "==", auth.currentUser.email)
          .get();
        myPosts = snapshot.docs.map(collectIdsAndDocs);
        console.log(myPosts);
        setPosts({ myPosts });
      };
      getPost();
    }, []);
    return (
      <View>
        <Text>{/*how do I print out values here!? I see them in console*/}</Text>
      </View>
    );
  };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Since you already calls the setPosts useState hook, you can access posts in your rendering code:

return (
  <View>
     {posts.map((post) => (
       <Text>{post.id}</Text>
     ))}
  </View>
);

To solve the null problem, pass in an empty array as the initial value when you define the state:

const [posts, setPosts] = useState([]);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!