【问题标题】:mapDispatchToProps shorthand causing flow type checking errormapDispatchToProps 简写导致流类型检查错误
【发布时间】:2018-11-29 18:24:14
【问题描述】:

我想使用mapDispatchToProps 的简写符号,但是当我替换老式的bindActionCreators 策略时

function mapDispatchToProps(dispatch: Dispatch<any>): PropsFromDispatch {
  return {
    fetchStuff: () => dispatch(fetchStuffAction()),
  };
}
....
export default connect(mapStateToProps, mapDispatchToProps)(MyComponent);

使用mapDispatchToProps 速记对象语法

const actions = {
  fetchStuff: fetchStuffAction,
};
...
export default connect(mapStateToProps, actions)(MyComponent);

我从流类型检查器收到以下投诉...

Cannot call connect because:
 • Either a callable signature is missing in object literal [1] but exists in MapDispatchToProps [2].
 • Or a callable signature is missing in object literal [1] but exists in MapDispatchToProps [3].

有什么想法吗?

react-redux v5.0.7 flow-bin v0.69.0

【问题讨论】:

标签: javascript redux flowtype


【解决方案1】:
mapDispatchToProps = (dispatch: Dispatch<*>) => ({
  fetchStuff: () => dispatch(fetchStuffAction())
})

你需要这样做。调度类型不是任何..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-31
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    相关资源
    最近更新 更多