class Counter extends Component {
constructor(props) {
super(props);
this.state = {
age: 10,
};
}
handleincrement = () => {
console.log("hy");
this.setState((prevState) => {
return { age: prevState.age + 1 };
});
}
render() {
return (
<div>
<button onClick={this.handleincrement}>
counter value is {this.state.age}
</button>
</div>
);
}
}
function App() {
return (
<div>
<Counter />
<Counter />
</div>
);
}
I have a one component Counter and i am using is 2 time times in App.js class when i click first button it result in increasing state value of only first Counter component and vice verse. My question is that why these both components behave independentaly from each other?