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

155
Visualizações
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 à 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