问题描述
我对 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);
});
}
}
解决方法
你必须使用异步和等待:
export const fetchState = async (e) =>{
await axios.get('http://localhost:8080/StatesByCountry/'+ e.target.value)