【问题标题】:Parameter value sent to but not received by action动作发送但未接收的参数值
【发布时间】:2019-01-17 07:44:06
【问题描述】:

我通过此操作启动加载扫描:

export function loadPickingScans (orderReference) {
    return { type: SCANNING_LOAD_SCANS, orderReference };
}

在我的智能(页面)组件中调用:

componentDidMount() {
    const { loadPickingScans } = this.props;
    loadPickingScans(this.props.match.params.orderReference);
}

这是网址:

enter code herehttp://localhost:3000/orders/my-order-reference/scans

this.props.match.params.orderReference 正确包含my-order-reference

但是,将日志添加到我的操作中,orderReference 将作为undefined 接收。

我应该怎么做才能收到这个期望值?

更新

根据要求:

function mapDispatchToProps(dispatch) {
    return {
        loadPickingScans: () => dispatch(loadPickingScans())
    };
}

【问题讨论】:

  • 能分享一下页面组件的代码吗?
  • 你能给你看看 mapDispatchToProps
  • 问题已更新。

标签: javascript reactjs ecmascript-6 redux react-redux


【解决方案1】:

mapDispatchToProps 中,在调度操作时,您没有向它传递任何参数,因此它在方法中记录未定义,您需要像这样编写它

function mapDispatchToProps(dispatch) {
    return {
        loadPickingScans: (value) => dispatch(loadPickingScans(value))
    };
}

或者干脆

const mapDispatchToProps = {
   loadPickingScans
}

【讨论】:

  • 是的,当你要求这个信息时,我的便士掉了,但是很好!
  • 很高兴能帮上忙 :-)
猜你喜欢
  • 1970-01-01
  • 2013-06-18
  • 1970-01-01
  • 2016-01-29
  • 1970-01-01
  • 2021-09-19
  • 2020-01-16
  • 1970-01-01
  • 2018-09-30
相关资源
最近更新 更多