I have started learning React and I am not able to understand why is the console.log logging twice. Below is my code and when I inspect it in chrome it shows the word 'random-text' twice instead of once.
import React, { Component } from "react";
class Counter extends Component {
state = {
count: 0
};
render() {
console.log('random-text');
return (
<div>
<span className={this.getBaadgeClasses()}>{this.formatCount()}</span>
<button
onClick={this.handleIncrement}
className="btn btn-success m-2"
>
Increment
</button>
{/* <ul>
{this.state.tags.map((tag) => (
<li key={tag}>{tag}</li>
))}
</ul> */}
</div>
);
}
getBaadgeClasses() {
let classes = "badge m-2 badge-";
classes += this.state.count === 0 ? "warning" : "primary";
return classes;
}
formatCount() {
const { count } = this.state;
return count === 0 ? "Zero" : count;
}
handleIncrement = () => {
this.setState({count: this.state.count + 1})
}
}
export default Counter;