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

304
Visualizações
How to rewrite the code using conditional rendering in react and javascript?

i have code like below

const mode = isActiveMode;

{!isActiveMode && runId && !isEmpty(items) && (
    <>
        <Flex>
            //more jsx similar
            <Icon onClick={() => 
                setItemState((previous: any) => ({
                    ...previous,
                    items: undefined,
                }))
            }
        />
        <TabPanel>
            <Table />
        </TabPanel>
    </>
)}

{isActiveMode && runId && !isEmpty(items) && isTableOpen && (
    <>
        <Flex>
            //more jsx similar
            <Icon onClick={() => 
                setItemState((previous: any) => ({
                    ...previous,
                    items: undefined,
                }))
            }
        />
        <TabPanel>
            {selections.length === 1 ? (
                <Table/> ): ( <div>hello</div>)
            }
        </TabPanel>
        
            
    </>
)}

i have two renderings based on different conditions. the code inside is almost same in both cases. how can i reuse the code in this case. could someone please help me with this.

How can i rewrite above code into one with conditions using reusable code. thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

From what I can see your jsx is pretty similar how about that one condition which was different you put it in ternary operator because table was rendering

const mode = isActiveMode;

{!isActiveMode && runId && !isEmpty(items) && (
    <>
    <Flex>
        //more jsx similar
        <Icon onClick={() => 
            setItemState((previous: any) => ({
                ...previous,
                items: undefined,
            }))
        }
     />
     <TabPanel>
         {isTableOpen===false || selections.length === 1 ? (
             <Table/> ): ( <div>hello</div>)
         }
     </TabPanel>
    
        
    </>
)}

Tell me if this isn't what you were looking for I'll try something different then

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