Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!