BACK
Use casesSubmit protection — guarding against double submission
Use cases · 03

Submit protection — guarding against double submission

Pattern

When a user double-clicks "Submit", without protection the server receives two identical requests. We want: the first click starts the request, and later clicks are ignored until it finishes.

How exhaustMap differs from switchMap

  • switchMap cancels the previous request and starts a new one — bad for a submit: the previous attempt might have almost saved.
  • exhaustMap ignores new values until the inner stream completes. That's exactly the behavior a submit needs.

What we achieve

No duplicate requests, and no need to disable the button by hand.

script.ts // TypeScript
CONSOLE · Console output
Hit Run to see the result...