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

336
Vistas
Why does the react function execute twice, but the console only prints once?

everyone. I'm learning react recently. I learned a lesson As this link says, the react function loads twice. But when I verified it, I found that it did load twice, but the Chrome browser only printed once. I wonder why? Here is the code I verified.

let count = 0;
function App() {
const [state, setState] = useState(1);

count++;
console.log(count);
console.log(`I have run ${count} time(s)!`);
return (
   <div>
     <button onClick={() => setState((e) => e + 1)}>{state}</button>
   </div>
);

Here is the result of chrome executionenter image description here

I think chrome should concole.log

1 App.js:9 I have run 1 time(s)! 2 App.js:9 I have run 2 time(s)!

I want to know why. Thank you.

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