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

592
Views
Uncaught TypeError: (intermediate value)(intermediate value)(intermediate value).map is not a function

I am building a React app that is requesting data from an an Api.here i am fecting data from api and i want to display it on a table. I am using ReactJS in frontend and NodeJS in backend.

here is my code.

import React, { useState, useEffect } from "react";
    import '../all.css';
    import Axios from "axios";

    function SearchProduct() {
        const [products, setProducts] = useState([]);


        const fetchProducts = async () => {
          const { data } = await Axios.get(
             "http://localhost:8080/api/QueryProductById/1"
        
            );
        
            let parseData = JSON.parse(data.response)

        
            setProducts(parseData);
        
        };
        
        const display = () => {
        
          return (products ?? []).map(product => (
            <tr key={product.id}>
               <th>{product.id}</th>
               <th>{product.name}</th>
               <th>{product.area}</th>
               <th>{product.ownerName}</th>
               <th>{product.cost}</th>
             </tr>
           ) );
          
         }
        useEffect(() => {
          fetchProducts();
        }, []);
        
        
          return (
            
            <div>
        
        <table>
          <thead>
            <tr>
              <th>ID</th>
              <th>Name</th>
              <th>Area</th>
              <th>Owner Name</th>
              <th>Cost</th>
        
            </tr>
          </thead>
          <tbody>
          {display()}
        
          </tbody>
          
         
        </table>
            </div>
          
          
          )
        }
        
export default SearchProduct;

i am getting uncaught error.

typeof data.response //is string


typeof products //is object

I have done almost every solution available but still can't resolve my error.

screenshot of error i am getting

screenshot of data in the API

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

try this code:

import React, { useState, useEffect } from "react";
import "../all.css";
import Axios from "axios";

function SearchProduct() {
  const [products, setProducts] = useState([]);

  const fetchProducts = async () => {
    const { data } = await Axios.get(
      "http://localhost:8080/api/QueryProductById/1"
    );

    let parseData = JSON.parse(data.response);

    setProducts(parseData);
  };

  useEffect(() => {
    fetchProducts();
  }, []);
//console.log(products)
  return (
    <div>
      <table>
        <thead>
          <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Area</th>
            <th>Owner Name</th>
            <th>Cost</th>
          </tr>
        </thead>
        <tbody>
          {products?.map((product) => (
            <tr key={product.id}>
              <th>{product.id}</th>
              <th>{product.name}</th>
              <th>{product.area}</th>
              <th>{product.ownerName}</th>
              <th>{product.cost}</th>
            </tr>
          ))}
        </tbody>
      </table>
    </div>
  );
}

export default SearchProduct;
about 4 years ago · Santiago Trujillo 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!