in f7 react store , are actions capable of being async ?
im using self calling async function inside action for now, but is it possible to use async action ?
Yes, it must return Promise to be async
is it ok like this ?
async getPersons({ state }, done) {
state.isLoading = true;
try {
const { data: persons } = await axios({
baseURL: f7.params.API_BASE_URL,
url: f7.params.PERSONS_ENDPOINT
});
state.persons = persons;
} catch (error) {
console.log(error);
} finally {
state.isLoading = false;
done();
}
},
Should work, yes, or like this
getPersons({ state }) {
state.isLoading = true;
return await axios({
baseURL: f7.params.API_BASE_URL,
url: f7.params.PERSONS_ENDPOINT
}).then(({data: persons}) => {
state.persons = persons;
}).catch((err) => {
console.log(err);
})
.finally(() => {
state.isLoading = false;
})
},
And you can use it like so to avoid passing done
callback here:
dispatch('getPersons').finally(() => {
})
2 Likes
thank you, its much better your way