0
我想使用做出反應,終極版與打字稿到dipatch的動作,但是當我使用mapDisPatchToProps()
,我不知道如何定義的dispatch
類型,有我的代碼:打字稿反應-redux
這是組件文件:
import * as React from 'react';
import Content from '../component/content';
interface Props {
allCityInformation: {'cityName': string, 'img': string}[];
onGetAllCityInformation: Function;
}
class HomePage extends React.Component<Props> {
componentDidMount() {
this.props.onGetAllCityInformation();
}
render() {
return (
<div>
<Content/>
</div>
);
}
}
export default HomePage;
這是我的容器文件:
import { connect } from 'react-redux';
import HomePage from '../pages/homePage';
export type DispatchGetCityInformation =() => void;
const mapDispatchToProps = (dispatch: DispatchGetCityInformation) => {
return{
onGetAllCityInformation: dispatch(getCityInformation())
};
};
export default connect(() => {return {};
}, mapDispatchToProps)(HomePage);
現在,該錯誤信息是: enter image description here
那麼,如何解決這個問題呢?
檢查這個話題:https://stackoverflow.com/questions/46055018/shorter-way-to-mapdispatchtoprops-using-react-redux-and-typescript – niba