0

I have a function fundBalance action function get called and inside of this function there and api call and after the api call resolved and i call the handleFundBalanceSuccess this error happens "Actions must be plain objects. Use custom middleware for async actions. React native"

    export function fundBalance(navigation) {
        return async (dispatch) => {
            dispatch({
                type: Fund_Balance_START
            })
            let response = await api.Fund_Balance(),
                responseJson = await response.json();
            if(response.status == 200){
                dispatch(handleFundBalanceSuccess(responseJson, navigation, dispatch)) // this line return Actions must be plain objects. Use custom middleware for async actions
            }
        }
    }

and the handleFundBalanceSuccess

handleFundBalanceSuccess = (response, navigation, dispatch) => {
    dispatch({
        type: Fund_Balance_SUCESS,
    })
    navigation.navigate('MessageScreen', {
        title: 'Success',
        description: response.status,
        doneClick: this.fundBalanceOrCashOutSuccessAction.bind(this, navigation),
    })
}
1
  • 1
    remove dispatch(handle....) to handleFundBalanceSuccess(responseJson, navigation, dispatch) Commented Jul 2, 2020 at 13:35

2 Answers 2

1

For dispatching functions, you would need redux-thunk middleware. Without this middleware, dispatch would only expect object parameters.

For more details on redux-thunk and how to implement it, you can check here - https://github.com/reduxjs/redux-thunk#motivation

However, in this case, you don't need to dispatch the function. Just calling the function would solve this.

Sign up to request clarification or add additional context in comments.

Comments

0

Inside the handleFundBalanceSuccess method you need to return plain object. For example this one in your case:

handleFundBalanceSuccess = (response, navigation, dispatch) => {
. . . . .
. . . . .
. . . . .
  return {
   type: Fund_Balance_SUCESS,
  };
}

Comments

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.