Czy moze ktos mi wskazać błąd co robie nie tak? wyszukiwarka wyszukuje gdy wpisze tekst ale gdy skasuje cały tekst powinna zwrocic wszystkie wyniki, a tego nie robi
<input type="text" placeholder="Szukaj.." value={this.state.search} onChange={this.searchingRoute} />
searchingRoute = (e) => {
this.setState({
search: e.target.value
})
if (this.state.search.length === 0) {
fetch(`http://api/Routes`, {
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + sessionStorage.getItem("access_token")
}
})
.then(response => {
if (response.ok) {
return response;
}
throw Error(response.status)
})
.then(response => response.json())
.then(data =>
this.setState({
trasy2: [...data],
})
)
.catch(error => console.log(error))
}
fetch(`http://api/Routes/Search?word=${this.state.search}`, {
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + sessionStorage.getItem("access_token")
}
})
.then(response => {
if (response.ok) {
return response;
}
throw Error(response.status)
})
.then(response => response.json())
.then(data =>
this.setState({
trasy2: [...data],
})
)
.catch(error => console.log(error))
}