Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
React App: Need advise on mapping json data into table

I have to fetch data from an api and map it to table. This is my code. Would anyone please advise the map function? Thank you.

import { useEffect, useState } from 'react';
import axios from 'axios';

const MovieList = () => {

    const [movies, setMovies] = useState([]);
    useEffect(() => {
    const fetchItems = async () => {
      const result = await axios(
        `api endpoint url`
      )
      setMovies(result.data)
    }
    fetchItems()
  }, [])
    
  return (
    #omit codes for table heads 
          <tbody>
          {movies.map(movie => (
            <tr>
                <td>{movie.results.year}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
                <td>{}</td>
            </tr>
            ))}
          </tbody>
}
export default MovieList;

enter image description here

enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Update movies as

setMovies(result.data.results)

Then instead of

movies.map()

use

movies[0].films.map(movie => {})

about 4 years ago · Juan Pablo Isaza Denunciar

0

Seems you have a response that is result is an array of films (another array) in each year. So, the ugly way is just iterate carefully through these arrays, e.g:


      {movies.map((movie: any) => {
        movie.results.map((yearData: any) => (
          <tr>
            <td>{yearData.year}</td>
            {yearData.films.map((film: any) => (
              <Fragment>
                <td>{film['Detail URL']}</td>
                <td>{film.Film}</td>
                <td>{film['Producer(s)']}</td>
                <td>{...etc}</td>
              </Fragment>
            ))}
          </tr>
        ));
      })}

But if you can make the response better in backend, or perform some pre-processing of the result in the frontend, I suggest you to respond the films grouped by year, that would make everything easier. For example:

[
  { 
    year: '2021',
    films: [{...}]
  },
  { 
    year: '1973',
    films: [{...}]
  },
  { 
    year: '1927 / 28 [A] (1st)',
    films: [{...}]
  },
  ...
]

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda