Reputation: 33
I have the following action in a react-native application. I receive the error "dispatch is not a function. I am new to redux and struggle with async actions. Is there a way to set the Asyncstorage to the state without using async/await?
export const balanceCall =async (dispatch) => {
let token = await getAsyncStoreT();
let mobile= await getAsyncStoreM();
balanceURL = `https://localhost/v1/user/find?token=${token}&mobile=${mobile}`;
console.log(balanceURL);
axios({
method: 'get',
url: checkURL,
}).then(function (response) {
let balance =response.data.map(user=>user.balance);
dispatch(balanceReceived(balance));
})
.catch(function (error) {
console.log(error);
console.log("NOT AGAIN");
});
};
Upvotes: 0
Views: 652
Reputation: 610
balanceCall
should be returning a function that takes dispatch as an argument. change the code accordingly .
export const balanceCall = () => async dispatch => {
let token = await getAsyncStoreT();
let mobile= await getAsyncStoreM();
balanceURL = `https://localhost/v1/user/find?token=${token}&mobile=${mobile}`;
console.log(balanceURL);
axios({
method: 'get',
url: checkURL,
}).then(function (response) {
let balance =response.data.map(user=>user.balance);
dispatch(balanceReceived(balance));
})
.catch(function (error) {
console.log(error);
console.log("NOT AGAIN");
});
};
Upvotes: 2