Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

288
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!