Jako ze odpowiedz przychodzi po okolo 1 sekundzie chcialbym wyłączyć na ten czas możliwość kilkania w buttona i włączyć gdy przyjdzie odpowiedz z serwera. Czy jest to mozliwe?
appendElement = (Name, Description, X, Y, RouteId) => {
const newItem = {
"Name": Name,
"Y": Y,
"X": X,
"RouteId": 1,
"Description": Description
}
fetch("http://api/Points", {
method: "post",
headers: {
"Content-Type": "application/json",
"Authorization": `bearer ${sessionStorage.getItem("access_token")}`
},
body: JSON.stringify(newItem)
})
.then(res => res.json())
.then(res => {
this.setState({
PointId: [...this.state.PointId, res.Id]
})
alert("dodales")
})
this.setState({
elements: ([...this.state.elements, { Name, Description, X, Y, RouteId }]),
})
w render mam:
<button className="btn" onClick={() => this.appendElement(this.state.Name, this.state.Description, this.state.Y, this.state.X, this.state.RouteId)}>Dodaj punkt</button>