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

130
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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