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

176
Views
Is this pattern of coding in react.js right?
import Connect from './connect.svg'
import Explore from './explore.svg' 

export const SomeComponent = props => {
    const someArray = [
        {text: "first", image: Connect},
        {text: "second", image: Explore}
    ]

    return ( 
        <div> 
            {someArray.map(item => (
                <img src={item.image} alt="some text" />
                <div> {item.text} </div>  
            ))}
        </div>
    )
}

I have used this method of setting an image property in objects to the corresponding images I imported, and then looping all through to output things like <li> etc. Everything seems to work fine but I want to confirm whether this is a bad way to code or not.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In my opinion it's a good component. However, I think that to render both <img> and <div> element as siblings you may need to group them as children of a Fragment (eg. <> </>). Finally, its a good practice to specify a key. The example below has the suggested changes.

import Connect from "./connect."
import Connect from './connect.svg'
import Explore from './explore.svg' 

export const SomeComponent = props => {
    const someArray = [
        {text: "first", image: Connect},
        {text: "second", image: Explore}
    ]
    return ( 
        <div> 
           { someArray.map ((item, key) => (
            <>
                <img src={item.image} alt="some text" key={key}/>
                <div key={key}> {item.text} </div>  
            </>
            )}} 
        </div>
    )

}

I hope that my opinion will be helpful.

about 4 years ago · Juan Pablo Isaza Report
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!