Reputation: 33
I am new to react and what to understand why the console.log is called twice when inside of the render function ?
import React, { Component } from "react";
import "./App.css";
class App extends Component {
render() {
console.log("Prints twice in console");
return (
<div className="App">
</div>
);
}
}
export default App;
Where as if i dont extend from component and use function instead the console prints only once
import React from "react";
import "./App.css";
function App() {
console.log("prints once");
return <div className="App"></div>;
}
export default App;
Upvotes: 3
Views: 266