Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda