Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda