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

110
Views
setInterval triggering the method twice in react component

I want to use setInterval to trigger my method after every set duration, but when I am using it in react component it is triggering the method twice after set duration.

Example: App.js code

function App() {
 setInterval(() => {
   console.log("in app");
 }, 1000);
}

export default App;

I am getting 2 "in app" message every second instead of once.

The same thing I tried in index.js file

Example: index.js

import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';


setInterval(() => {
  console.log("in index");
}, 1000);


const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

In this case I can see "in index" every second in console. (which is what I was expecting in App.js as well)

See attached console image as well.

console

Is this an expected behavior?

More info: I created the project using npx create-react-app test and edited App.js file.

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