Why my render method is react called twice

it’s probably because of React StrictMode in your index.js file (if you use create-react-app).

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);
serviceWorker.unregister();

strict mode checks for potential problems and caused to run some lifecycle methods twice (like constructor, render, componentShouldUpdate, etc).

Strict mode checks are run in development mode only; they do not impact the production build.

you can read more about it on strict-mode

Leave a Comment