function getSuggestions(inputValue) {
let results = [];
axios.get(`${API_URL}?queryString=${inputValue}`)
.then(({ data }) => {
results = data;
})
let textValues = results.map(r => (textValues.push(r.text.toUpperCase())));
//push all unique values to Set
let uniqSet = new Set(textValues);
//turn Set into Array object
let uniqArr = Array.from(uniqSet)
let suggestions = uniqArr.map(r => (suggestions.push({'label': r.text.toUpperCase()})));
return suggestions.filter(suggestion => {
const keep =
(!inputValue || suggestion.label.toLowerCase().includes(inputValue.toLowerCase())) &&
count < 5;
if (keep) {
count += 1;
}
return keep;
});
}
I have this function to create an auto-complete search component where I take an inputValue entered by the user and send it to an endpoint which then returns an object of search terms.
I am attempting to set this empty results
array to the data
object that is returned from my fetch with axios. No matter what I try though, the results array always stays empty. Any suggestions? Thank you in advance.