Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React : Handle multiple browser(s), browser tabs to restrict duplicate operations

I have a button Submit when clicked performs some operation calling an API. Post click, the button is disabled or basically the initial state of the button and the operation is changed.

I have two or multiple browser tabs which shows same screen of Submit. If in any one of the tab, the Submit operation is performed, the other tabs should show the updated version. The other tabs should show the disabled version and should not show the initial state.

How do I achieve this? I am using React, JS

enter image description here

like image 470
Matarishvan Avatar asked Dec 11 '20 11:12

Matarishvan


1 Answers

#1 Data duplication MUST be restricted at the server side.

  • I would recommend some cache like node-cache. Node-cache will having scalability issues, so better to go with redis. (The logic should be smt. like: If the form has submited with the user_id, or with form_id, you can create a cache for that, and if you proceed it, store it in the db, other case throws an error. On the other browser you must validate before the submit if the unique_id neither in the cache nor in the db. If exists, you can throws an error in the nr.2 browser.

#2 If you want to disable the button, you have to use websockets

like image 53
Peter Avatar answered Nov 06 '22 22:11

Peter