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

134
Vistas
How to generate random image from Disney API

Hello I am using the Disney API using React, I am trying to figure out how to make a random characters image and name appear. The following code I can make one characters image and name appear which is great but I want it to grab a random character and make there name and image appear. The last two lines inside the [] the 0 represents the first character in the API Data if I change it to 1 it will display the second characters info in the API Data. For example disneyData[0].name returns the character name 'Olu Mel' if I change the 0 to a 1 it will return the character name "GIFfany". I have also attached a image of how the Disney API Data returns, just learning API and just struggling to read it and return its data. Hope my explanation is easy to understand. Thanks for you help.

Disney API returns character data like this

import request from 'superagent'
// import { fetchDisney } from '../apiClient'

function App () {
  // const [data, setData] = useState(null)
  const [disneyData, setDisneyData] = useState(null)
  const [loading, setLoading] = useState(true)

  console.table(disneyData?.data)

  useEffect(() => {
    // console.log('useEffect')
    request.get('https://api.disneyapi.dev/characters')
      .then(response => {
        setDisneyData(response.body.data)
        console.log(response.body.data)
        setLoading(false)
        return null
      })
      .catch(err => (
        console.log(err)
      ))
  }, [])
  // if its loading then display 'loading content' else display
  if (loading) return 'loading content'
  return (
    <>
      <h1>Experimenting on Disney Characters</h1>
      <h2>{disneyData[0].name}</h2>
      <img src={disneyData[0].imageUrl} alt="" />

    </>
  )
}

export default App
about 4 years ago · Juan Pablo Isaza
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