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

158
Vistas
How to preserve state on specific conditional rendering?

I have a page on react, where I have so that when the user is on a desktop screen size, it shows both components together, but on smaller screens it shows only one with the ability to switch. Right now I'm using a custom hook that returns a boolean called desktop (true if desktop size, false if not). I'm also using a state variable to track the change between components.

{!desktop ?
   switch ?
         <>{List}</>
      :
         <>{Map}</>
   : 
   <>{Map}{List}</>
}

When switching between desktop/not, it resets the state on both components. I understand that this is what the above code is supposed to do, because you're rendering a new instance of the component.

My question is there a better way to achieve my desired outcome with a different conditional render? And if not is there a way to preserve the state when desktop does switch? Any help would be greatly appreciated!

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