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

131
Views
How browser handle JavaScript with React

I would like to understand how browsers handle JavaScript once bundled with Webpack for example. In my understanding of the thing, is transmitted to the browser JavaScript code understandable by the browser, after transpilation of the React code with Babel and bundle of the different parts of an application, which means that there is no more code related to the React library right? And yet it is still possible to benefit from the functionalities for which React is used, but then where does React sit, how does the exchange with the browser happen? Is the React library somehow included in the bundled code?

I can imagine a scenario like this:

  • code including transpiled React code, is bundled on the server that hosts it
  • when page is requested by a user, are received the different files of the bundle including the JavaScript code, including then the React features used in application
  • the DOM is built
  • the JavaScript is evaluated by the JavaScript engine of the browser, and the events are attached to the DOM
  • when an event is triggered, the event executes the associated function
  • and here I have no idea what can happen, how the state is updated since there is no more code like "const [state, setState] = useState()", I just know that the DOM is virtually rebuilt to be compared etc... Is it a transpiled version "const [state, setState] = useState()"?

edit:

import {useState} from 'react';
const [state, setState] = useState();

I just tested this code and on Babel'site and it gives:

"use strict";

var _react = require("react");

const [state, setState] = (0, _react.useState)();

Does this mean that React is included in the bundle? If yes, how are the imports done by the browser (I've heard about module loaders but I have no idea if that's what it is, a search on the web doesn't give me any result)?

Thanks in advance for your answers

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In short answer, Webpack does everything for you. It does all the dependency check to make sure what are needed and should go to the bundle. (It also makes sure the unused libraries won't go into the bundle, even your own modules if they are not referenced) It bundles you own code and all the necessary libraries, including React, you used into one optimizely minimized file for you. Your app load that file in the index.html so the browser can execute the code that you desire.

When you run you react app in you local env, in the home page, ie: http://localhost:3000/, click on view-source, you will see this line

<script defer src="/static/js/bundle.js"></script>

that's where your code and the libraries are.

If you run npm run build, it will generate a even more optimized build for production env in the build folder. The structure of the index.html will be different than local env as well!

about 4 years ago · Juan Pablo Isaza Report
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!