0

I'm very new to redux. I tried my best to resolve this error in redux but it still gives me an error. The error is message is:

Error: Actions must be plain objects. Use custom middleware for async actions.

Please help me resolve this.

The error points to the line after return. Here is my code:

    const mapDispatchToProps = (dispatch) => {
      return{
        fetchState: (e) => dispatch(fetchState(e)),
        fetchCapital: (e) => dispatch(fetchCapital(e))
      }
    }

And fetchState is defined in my action.jsx

export const fetchState = (e) =>{
    console.log(e.target)
    return (dispatch) => {
        console.log("hey")

        axios.get('http://localhost:8080/StatesByCountry/'+ e.target.value)
                .then(response => {
                    const stateData = response.data || '';
                    dispatch(changeState(stateData));
            })
            .catch( err => {
                console.log(err);
            });
    }
}
buzatto
  • 9,704
  • 5
  • 24
  • 33
rove
  • 11
  • 3

1 Answers1

0

You have to use async and await :

export const fetchState = async (e) =>{

await axios.get('http://localhost:8080/StatesByCountry/'+ e.target.value)
buzatto
  • 9,704
  • 5
  • 24
  • 33