My async/await
function:
async function search(pattern) {
const res = await axios.get("/api/searchIndex.json");
const index = res.data;
const options = {
keys: ["title", "content"],
shouldSort: true,
threshold: 0.5,
maxPatternLength: 50
};
const fuse = new Fuse(index, options);
return fuse.search(pattern);
}
Where it's called, and then I push the object to an array results
and then execute renderAutoComplete
function handleSearchInput(event) {
input = event.target.value;
if (input.length >= 3) {
results =[];
showAutoComplete = true;
search(input).then( val => results.push(...val)).then(renderAutoComplete());
}
}
But, in renderAutoComplete
results
always equals 0
and I can't access the data. So this means I have an issue somewhere in my async/await
.
Of course, if I console.log
I get: