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

289
Visualizações
React: rendering images before pressing the button

I've been trying to work on an image search react project where you can click and store images that you want after searching. Right now I am able to search for and show the image as buttons, but the images appear on the button only after you click it.

function Image(props) { 
  return (
  <button className = "photo" onClick = {props.onClick}>
    <img 
      width={200} height={200}
      src = {props.value} 
      alt = "" 
      onClick={myfunction()} />
  </button> ) 
}

These functions below are inside another class

handleClick(i){
    const image = this.state.image.slice();
    console.log(global.imageLinks);
    image[i] = global.imageLinks[i];
    this.setState({
      image: image,
    })
}

renderImage(i) {
    return (
        <Image 
        value = {this.state.image[i]} 
        onClick={() => this.handleClick(i)}
    />)
}

I tried deleting the onClick part in the button or moving the image section but it just causes a lot of errors. Is there any way so that the image will appear on the button as soon as it detects that the value is a link?

Many thanks!

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