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

74
Views
Suggestion to refactor code into simple way -React

I have multiple with the same class name and method with different parameter i want to refactor the below code to a simpler way any suggestion would be helpful.

<table class="greyGridTable">
  <tbody>
    <tr>
      <td>AA</td>
      <td className = 'table-container'>{formatDate(someMethod1(param1,a)}</td>
    </tr>
    <tr>
      <td>BB</td>
      <td className = 'table-container'>{formatDate(someMethod1(param1,b)}</td>
    </tr>
    <tr>
      <td>CC</td>
      <td className = 'table-container'>{formatDate(someMethod1(param1,c)}</td>
    </tr>
  </tbody>
</table>

I want to refactor the code with the same component.

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

0

I hope this would be helpful. thanks

export const TableItems = ({data}) => {
  return (
    <>
      {data.map(item => (
        <tr>
          <td>{item.name}</td>
          <td className='table-container'> {item?.symbol} {formatDate(someMethod1(param1,a)}</td>
        </tr>
      ))}
    </>
  )
}


const data = [
  {
    name: AA,
  },
  {
    name: BB,
  },
  {
    name: CC,
    symbol: '£'
  }
]

<table class="greyGridTable">
  <tbody>
    <TableItems data={data} />
  </tbody>
</table>
about 4 years ago · Juan Pablo Isaza Report

0

Try to use an array instead. Having reusable components in an array is easy to maintain, expand and read. Definitely a good practice.

let tableItems = [{name:"AA",date:new Date()},.....]

return (

<table class="greyGridTable">
  <tbody>
    {tableItems.map((item,index)=>{
     return(
       <tr>
         <td>{item.date}</td>
         <td className = 'table-container'>{item.date}</td>
       </tr>
     )
    })}
  </tbody>
</table>

)

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!