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

212
Views
Display Firestore Data with a datatype of map: Error: Objects are not valid as a React child

Retrieving from firestore:

const [product, setProduct] = useState([]);

  const getProducts = async () => {
    const querySnapshot = await getDocs(collection(db, "products"));
    const arr = [];
    querySnapshot.forEach((doc) => {
      arr.push({
        ...doc.data(),
        id: doc.id,
      });
    });
    setProduct(arr);
  };

  useEffect(() => {
    getProducts();
  }, []);

I have this colorMap retrieved from Firestore:

export const data = [
  {
    colorMap: { red: 6, blue: 7, green: 8 },
    id: "a4TK38mByQbim4TwOHMY"
  },
  
  {
    colorMap: { Black: 20, Gold: 10 },
    id: "m08YmrlFxhxLxyc3hVjT"
  },
  {
    colorMap: { green: 9, red: 19 },
    id: "nN2w57SiDovbtQ6EBzGb"
  }
];

How can I display it in the screen?

 {product &&
        product.map((index) => (
          <>
            <b>{index.prodName + "-" + index.size + index.cat}</b>
            <li>{index.id}</li>
          </>
        ))}

If I'll add this:

<li>{index.colorMap}</li>

It will cause an error:

Uncaught (in promise) Error: Objects are not valid as a React child (found: object with keys {green, red, blue})

How do I resolve this? Any help would be appreciated. Thank you

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use Object.entries() and then map those items as shown below:

{product &&
  product.map((index) => (
  <div>
    <b>{index.prodName + "-" + index.size + index.cat}</b>
    <p>{index.id}</p>
    <ul>
      {
        Object.entries(index.colorMap).map((color) => (
          <li>{color[0]} - {color[1]}</li>
        ))
      }
    </ul>
  </div>
))}
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!