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

130
Vistas
How to render based on AJAX result in react js?

Just want to render movie cards based on results that come from ajax call.

Currently, the movie cards components are rendered based on that hard code array named list. I just want to make it dynamic and replace it with my ajax data.

const getlist = async () => {
  const res = await fetch('http://localhost:3001/customize');
  const data = await response.json();
  getlist();
};

export default function Index() {

  const list = ['dexter', 'bb', 'got'];

  return (
    <>
      <main className={parentstyle.main_container}>
        <NavBar />
        <div className={style.searchbar_container}>
          <SearchBar />
        </div>
        <div className={style.card_container}>
          {test.map((element, i) => {
            return <MovieCard movieName={element} key={i} />;
          })}
        </div>
      </main>
    </>
  );
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use the useState hook to set up your component state (the list) and fetch data in a useEffect hook...

The Effect Hook lets you perform side effects in function components:

Data fetching, setting up a subscription, and manually changing the DOM in React components are all examples of side effects. Whether or not you’re used to calling these operations “side effects” (or just “effects”), you’ve likely performed them in your components before.

import { useEffect, useState } from "react"

const getlist = async () => {
  const res = await fetch("http://localhost:3001/customize")
  if (!res.ok) {
    throw new Error(`${res.status}: ${await res.text()}`)
  }
  return res.json()
}

const Index = () => {

  const [ list, setList ] = useState([]) // start with an empty array

  useEffect(() => {
    getList()
      .then(setList)
      .catch(console.error)
  }, []) // empty dependencies array, this runs only once

  return (
    // ...

    {list.map((element, i) => (
      <MovieCard movieName={element} key={i} />
    ))}

    // ...
  )
}

export default Index
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