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

157
Vistas
reactjs - separation ui and logic with lazy-loading

I want to separate my UI and logic to decrease the size of the bundle. I know I can separate the logic with the headless components approach or custom hooks, etc. but I also want to separate the logic from the bundle. I assume that I can achieve this by lazy-loading all logic and sending UI immediately.

I have created a codesandbox example to demonstrate what I want. There is a component called ui/index.js. It includes a component called <Logic {...props} />. The Logic component gets rendered when the enableLogic state is set to true when the UI component initially renders. The Logic component is lazy-loaded and returns nothing, null. The only purpose of the component is to render the logic.

const Logic = React.lazy(() =>
  import(/* webpackChunkName: "logic" */ "./logic")
);

My question is, having this kind of approach for simple, dummy components would be nonsense but sometimes, some part of the large application's logic can be heavy. I wonder if, separating the logic and UI with this kind of approach can cause me any trouble? Is this approach used by many people? Is there any kind of library that uses the same kind of approach to separate logic and UI with lazy-loading?

I believe that decreasing bundle size for pages with heavy logic can reduce the time that users will see pages.

You can have a look at the implementation via codesandbox link right here. Codesandbox

about 4 years ago · Santiago Gelvez
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