Reactjs 如何根据状态处理React Redux中的通知?

Reactjs 如何根据状态处理React Redux中的通知?,reactjs,redux,react-redux,es6-promise,Reactjs,Redux,React Redux,Es6 Promise,我有一个支持表单,在提交后从API传递成功消息。在form component类中,我得到了mapstateTrops(),它从减速器中获取值 function mapStateToProps(state) { return { contact_form: state.contact_form.all} } 为了向用户显示通知,我需要 if(this.props.contact_form.data) { notify_banner(" Your request is

我有一个支持表单,在提交后从API传递成功消息。在form component类中,我得到了mapstateTrops(),它从减速器中获取值

function mapStateToProps(state) {
  return { contact_form: state.contact_form.all}
} 
为了向用户显示通知,我需要

   if(this.props.contact_form.data) {
        notify_banner(" Your request is submitted successfully.","success",5000);
      }
这种方法的问题是,状态根本没有被清除。因此,每当用户转到“支持表单”页面时,此警报将显示为状态仍保持不变

在执行操作后,我在清除状态时查看了这个,但这会清空状态,并且警报根本不会显示


那么,如何只通知用户一次呢?

一种方法是在用户提交表单后发送成功操作。这里,我取flag=true,这意味着表单已提交。因此,您可以使用此检查来显示横幅通知

if(this.props.contact_form.flag) {
  notify_banner("Success");
  //disptach reset action here
}
通知后,立即通过调用resetState操作将contact_form.flag重置为false

export function resetState() {
   const request = {
     flag: false
     };

    return {
      type: CONTACT_FORM,
      payload: request
    };
}

您可以在
componentWillMount
componentWillUnmount
上发送重置操作。您可以在状态中添加一个标志,该标志将告诉您是否已“告知”(消息),并取决于此,是否显示;)如果只允许用户提交表单一次,则添加标志将起作用。如果用户想要提交多次,该怎么办?如果使用redux,请使用状态来触发通知组件。无论您需要多少通知,它都将扩展。ot您可以使用toaster redux npm进行通知,