Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

316
Views
How to handle notifications in React-Redux depending on state?

I have a support form that delivers success message from an API after submit. In the form component class, I got mapStateToProps() that gets value from the reducer.

function mapStateToProps(state) {
  return { contact_form: state.contact_form.all}
} 

and to show the notification to user, I do

   if(this.props.contact_form.data) {
        notify_banner(" Your request is submitted successfully.","success",5000);
      }

The problem with this approach is that the state is not cleared at all. So whenever the user goes to the support form page, this alert appears as the state still holds.

I had a look at this thread on clearing state after an action is performed, but this would empty the state and the alert woon't be displayed at all.

So how do I notify user just once?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

One way is to dispatch success action after user submits the form. Here, I take flag = true which means form is submitted. So you can have this check to show banner notification.

if(this.props.contact_form.flag) {
  notify_banner("Success");
  //disptach reset action here
}

after notification, instantly reset the contact_form.flag to false by dipatching resetState action.

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

    return {
      type: CONTACT_FORM,
      payload: request
    };
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!