I have a NetCore2 app with ReactJS installed.
My React app does something like this ->
- User inputs into a field
- axios makes a call to an api to get the user and/or list of users
- The input field shows suggestions based on what was saved in PeopleList state.
I'm using Office Fabric UI React - People Picker (in case it matters).
My problem here is that i have no idea how i could use async/await in my code.
If i put something like this
async asynconFilterChanged = (filterText, currentPersonas, limitResults) => {
VS Code throws an error telling me that async is only for .ts files. Also if i use await in any other functions i will get an error such as await is a reserved word
.
As far as i know async/await is not TS only...(or am i wrong?).
I'm using the older Babel with the ENV preset.
Let me know if i need to provide more code, but TLDR what i want is to only start the filter function after my axios is done pushing items into the PeopleList state (array of objects).
Thanks!
I have a NetCore2 app with ReactJS installed.
My React app does something like this ->
- User inputs into a field
- axios makes a call to an api to get the user and/or list of users
- The input field shows suggestions based on what was saved in PeopleList state.
I'm using Office Fabric UI React - People Picker (in case it matters).
My problem here is that i have no idea how i could use async/await in my code.
If i put something like this
async asynconFilterChanged = (filterText, currentPersonas, limitResults) => {
VS Code throws an error telling me that async is only for .ts files. Also if i use await in any other functions i will get an error such as await is a reserved word
.
As far as i know async/await is not TS only...(or am i wrong?).
I'm using the older Babel with the ENV preset.
Let me know if i need to provide more code, but TLDR what i want is to only start the filter function after my axios is done pushing items into the PeopleList state (array of objects).
Thanks!
Share Improve this question asked Nov 21, 2018 at 13:35 Dante R.Dante R. 9325 gold badges13 silver badges42 bronze badges2 Answers
Reset to default 15When using an arrow function you should write async/await like this:
const asynconFilteredChanged = async () => {
// code here
}
Check out Syntax for async arrow function
As per syntax try to follow above codebase,
asynconFilterChanged = async (filterText, currentPersonas, limitResults) => {
try {
await yourFucntion = (limitResults) => {
....Your logic...
}
} catch(error) {
console.error(error);
}
Yes, try to use and touch async-await guide