0

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");
    });
};

1 Answer 1

2

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");
    });
};
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the help. It seems to resolve the error, but the dispatch never happens. Do you have suggestions?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.