0

我对redux很陌生。我尽力解决了 redux 中的这个错误,但它仍然给我一个错误。错误是消息是:

错误:操作必须是普通对象。使用自定义中间件进行异步操作。

请帮我解决这个问题。

错误指向返回后的行。这是我的代码:

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

并且fetchState在我的 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);
            });
    }
}
4

1 回答 1

0

您必须使用 async 和 await :

export const fetchState = async (e) =>{

await axios.get('http://localhost:8080/StatesByCountry/'+ e.target.value)
于 2021-02-20T21:09:49.140 回答