the search engine does not work, namely: going into devtools and the network tab when I type e.g. cow I have http: // api / Routes / Search? word = co when I add spaces I have: http: // api / Routes / Search? word = cow and searches and when I delete everything, I get: http: // api / Routes / Search? word = c and eg I will add spaces then display all results as it should strange...
<input type="text" placeholder="search.." 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({
route: [...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({
route: [...data],
})
)
.catch(error => console.log(error))
}