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

109
Views
Split react component return

Sometimes I meet in code of other people constructions that look like this:

const TextField = () => {
  const renderLabel = () => {..}
  const renderInput = () => {...}
  const renderFooter = () => {...}
  
  return (
    <div>
      {
        renderLabel();
        renderInput();
        renderFooter();
      }
    </div>
  )
}

I understand why they use this way, cause it's can be situation when "return" is too small to split it to separate components and at the same time I want it to look more comfortable to udnerstand.

But only one questions here, why everywhere people use functions for these "renderLabel", "renderInput" and so on?

What cons of the way when I just create them as variables
const renderLabel = <div>...</div>
and then render it?

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

0

I don't know about those functions in your example, but I use such functions to generate the component that I need depending on a parameter.

For example, when I build tabs content I may write something like this:

layout:

<button onClick={() => setActiveTab('tab1')}>Tab 1</button>
<button onClick={() => setActiveTab('tab2')}>Tab 2</button>

<div>{generateTabContent(activeTab)}</div>

generate tab content function:

function generateTabContent(activeTab) {
  switch (activeTab) {
    case 'tab1':
      return <Tab1 />
    // etc...
  }
}

This function is pure (it accepts the param, instead of calling the state value), and can be extracted to utils folder if needed.

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!