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

101
Views
Getting object data from API and then displaying it (React Fetch)

I'm trying to extract the data from this API https://fe-assignment.vaimo.net/ to render the object name. It should be a drone sale item but I cant display it on mapping or such.

I only have to extract this items data and there are no other objects or such in the API. I want to eventually display the product with its image, and all its attributes but I am just trying to extract simple strings from the JSON like the product name.

The result of the above code when ran is simply the heading with no further content. Both console logs return the API data in full. See ComponentDidMount and render

import { render } from "@testing-library/react"
import React from "react"
import "./App.css"
import {useState, useEffect } from 'react'
import axios from 'axios'
import Colors from "./components/Colors"
import DetailsThumb from "./components/DetailsThumb"

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      items: [],
      isLoaded: false,
    };
  }

  

  componentDidMount() {
    fetch("https://fe-assignment.vaimo.net/")
      .then((res) => res.json())
      .then(data => { console.log(data)
        this.setState({
          isLoaded: true,
          items: data,
        });
      });
  }

  render() {
    let content = null
    var { isLoaded, items } = this.state;
    if (!isLoaded) {
      return <div>Loading..</div>;
    } else {
      console.log(items)
      if (items.data){
        content = items.map((product, key) => <div>{product.name}</div>)
      }
      return (
        <div>
          <h1>The drone page</h1>
          {content}
          </div>
      );
    }
  }
}

export default App;
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You are not getting a list of products, you are getting a single product, so instead of this:

if (items.data){
   content = items.map((product, key) => <div>{product.name}</div>)
}

You should do this:

if (items) {
  content = <div>{items.product.name}</div>
}
about 4 years ago · Juan Pablo Isaza Report

0

The problem is that you are storing the result of map function (an array) in a new array.

if (items.data){
    content = items.map((product, key) => <div>{product.name}</div>)
  }

You should do this

if (items.data){
    content = items.product.name
  }
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!