enter image description here can anyone solve thisenter image description here
Asked
Active
Viewed 31 times
-3
-
1Welcome to Stack Overflow! Relevant code and error messages need to be included in your question *as text*, not as pictures of text. Just linking to screen shots makes it more difficult for people to help you. To learn more about this community and how we can help you, please start with the [tour] and read [ask] and its linked resources. – David Dec 23 '21 at 17:20
-
As for the problem itself... `setState` is a *function*, not a value that you overwrite. [Call the function with the new state value.](https://reactjs.org/docs/react-component.html#setstate) – David Dec 23 '21 at 17:21
1 Answers
-1
I checked your code and I fixed the problems:
import React, { Component } from 'react';
export default class Classcompo extends Component {
constructor(props) {
super(props);
this.state = {
message: 'welcome visitors',
};
}
changeMessage() {
this.setState({
message: 'ok',
});
}
render() {
return (
<div>
<h1>{this.state.message}</h1>
<button onClick={() => this.changeMessage()}>CLICK</button>
</div>
);
}
}

Mohsen Mahoski
- 452
- 1
- 5
- 14