Я пытаюсь выяснить, как автоматически обновлять состояние после запроса исправления, чтобы при нажатии кнопки он автоматически добавлял их в счетчик.К сожалению, для обновления требуется загрузка страницы.Есть ли что-нибудь, что вы можете увидеть на этом?Спасибо за любую помощь, спасибо.
import React, { Component } from "react";
import "./Like.css";
class Button extends Component {
constructor(props) {
super(props);
this.state = {
counter: this.props.counter
};
}
handleSubmit = event => {
event.preventDefault();
fetch(`http://localhost:3001/api/tracklists/${this.props.id}`, {
method: "PATCH",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify({
tracklist: {
title: this.props.title,
url: this.props.url,
genre: this.props.genre,
tracklist: this.props.tracklist,
likes: this.props.counter + 1
}
})
})
.then(response => response.json())
.then(response => {
this.setState({
counter: this.props.counter
});
});
};
render() {
return (
<div className="customContainer">
<button onClick={this.handleSubmit}>{this.state.counter}</button>
</div>
);
}
}
export default Button;