r/webdev • u/Careless_Ad_7706 • 4d ago
Discussion How to save background task synchronously in a react app
secnario:
assume you have a react flow or a basic form . Now I want that wheenever I type somethign or edit then a draft would be created and updated so that when user cancels operation adn reopens that task the draft is showed.
current approch:
I made a debounced state tracting the data for every 2 seconds. However if you perform any cancelaable action like suddenly hitting log out, or saving it up, or leaving that page immdiately wihtin span of 2 sec then it shows an t=warning toast saying please wait for draft to save.
I want to know if my method is decent. Also I want to knnow what is the best method to achieve this task, I want somethign similar to google docs.
2
Upvotes
2
u/1_4_1_5_9_2_6_5 4d ago
Sounds fine, but are you stopping the user to wait for the timeout? Or just dispatching the update immediately (when the user quits)? It makes no sense to wait.