react-redux の connect の型について
code:javascript
// Casting to prevent error where used in index.ts that isBusy is mandatory, since it is being provided by Redux.
export default withRouter(
connect<{}, {}, IAppProps>(mapStateToProps, mapDispatchToProps)(App)
) as React.ComponentClass<{}>;
furuk4wa.iconこれコンパイルを実行していないのでどうなるか知らん
もし、 mapStateToProps, mapDispatchToProps それぞれに型をつけたい場合こうするのがよい
code:javascript
interface StateProps {
hoge: string
}
const mapSateToProps = (state: RootState): StateProps => {
return { hoge: state.hoge }
}
interface DispatchProps {
foo: () => void
}
const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => {
return { foo: dispatch(foo()) }
}
interface Props extends StateProps, DispatchProps {}
export default withRouter(
connect<StateProps, DispatchProps, Props>(mapStateToProps, mapDispatchToProps)(App)
) as React.ComponentClass<{}>;