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

130
Views
Should I create new component or render js conditionaly?

I have a case where I need to render one react component again in a different place. So, for example, I have an index component where I have a list of users and filters for this list. Now I need to render this component in a different place but without filters. Should I create a new almost the same index component and skip rendering filters or should I pass prop and render conditional JSX?


const Index = ({ renderFilters }) => {
  ... some code
  return (
    <>
      ...some jsx code
      { renderFilters ? <Filters /> : null }
      <UserList>
      ...some jsx code
    </>
  )
}

or just copy-paste the index component and


const IndexWithouFilters = () => {
  ... some code
  return (
    <>
      ...some jsx code
      <UserList>
      ...some jsx code
    </>
  )
}

Of course, this is only an example and I have a case where have to render conditionally more than one components.

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

0

It is a best practice in Reactjs to reuse components.So go with former approach.

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!