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

129
Visualizações
How to handle Conditional Rendering properly

The question is how to Hide/Show components properly.

Example. Basic popup modal component:

const Modal = ({children, isOpen}) => {
    const [value, setValue] = useState(0)

    const functionOne = () => {
        doSomething
    }

    return (
        <div>
            {children}
        </div>
    )
}

If i want to Show/Hide this modal window, I have 2 options.

a) Toggle rendering in parent component

<div>
    {showModal && <Modal />}
</div>

b) Toggle rendering inside Modal component

...
const [value, setValue] = useState(0)

if (!isOpen) {
    return null
}

...

Option B seems more elegant, because it hides logic inside component. But all unrendered components are still shown in React component tree, containing all variables. This method provided in official docs Preventing Component from Rendering and being used by Material UI.

Option A not so elegant, but it makes component tree much smaller, because all hidden components are not added to the React component tree.

What is the Best Practice in that situation? Do unrendered components in component tree have any significant impact on the performance, or could be ignored?

about 4 years ago · Juan Pablo Isaza
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