I am rendering a simple react component, where no state and props are set
I am logging text to console only once inside the render function but it's logged twice:
rendering counter
rendering counter
Below is the code of the component counter.js
import React, { Component } from "react";
class Counter extends Component {
render() {
console.log("rendering counter"); //this is printed two times
return <span className={"badge m-3 badge-primary"}>counter</span>;
}
}
export default Counter;
And index.js
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import * as serviceWorker from "./serviceWorker";
import "bootstrap/dist/css/bootstrap.css";
import Counter from "./components/counter";
ReactDOM.render(
<React.StrictMode>
<Counter />
</React.StrictMode>,
document.getElementById("root")
);
serviceWorker.unregister();
it seems that the render function in the component is called two times. But why is that?