i make simple app with react.js that suggestion random place every time click on Button the problem can not re-render component after one click how can i get new place each time click on button
place.js where fetch API to get data
state = { loading: true, person: null };
async componentDidMount() {
let Xyurl = "https://cors-anywhere.herokuapp.com/";
let url =
"https://wainnakel.com/api/v1/GenerateFS.php?uid=26.2716025,50.2017993&g et_param=value";
let response = await fetch(Xyurl + url);
let data = await response.json();
this.setState({ place: data, loading: false });
}
render() {
return (
<div>
<div>
{this.state.loading || !this.state.place ? (
<div>loading......</div>
) : (
<div className="PlcseContiner">
<img alt="description" src= .
{this.state.place.image[0]} />
{this.state.place.name}
</div>
</div>
);
Suggestion where from button can render places
class Suggestion extends Component {
constructor(props) {
super(props);
this.state = {
visible: false
};
this.handleClicked = this.handleClicked.bind(this);
}
handleClicked(event) {
event.preventDefault();
this.setState({
visible: true
});
}
generateplace() {
if (this.state.visible) {
return <Place />;
}
return null;
}
render() {
return (
<div className="main-button">
<Button onClick={this.handleClicked} color="warning" className="Btn">
suggestion
</Button>
{this.generateplace()}
</div>
);
}
}