Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda