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