jollyjerr / react-autosave

Component or hook to auto save controlled form values as they are updated
https://www.npmjs.com/package/react-autosave
MIT License
65 stars 2 forks source link

Doesn't save state to db quickly before creating new item? #11

Closed deadcoder0904 closed 2 years ago

deadcoder0904 commented 2 years ago

Hey this is an amazing library but I do have an issue that I'm currently facing.

I have a simple app like this:

Docs App

I click on New Docs, type in quickly something & then click on New Docs again before it saves.

There is an indicator beside it that shows Saving & Saved state. When it's on Saving state & I switch to New Docs, it keeps the old doc empty because the state hadn't been saved.

See the new image below:

Screenshot 2021-12-28 at 4 43 58 PM

I did type in something quickly but clicked on New Docs immediately so it kept that part empty. 1st & 2nd item has Empty Docs in it (see image)

How do I fix it?

I have a full repro at https://github.com/deadcoder0904/docs-autosync/tree/react-autosave (see 2 files: DocsList.tsx & Writer.tsx)

Also, I'm wondering if alertIfUnsavedChanges is good to implement. https://github.com/lukesmurray/react-query-autosync has a similar option (search for alertIfUnsavedChanges on the readme) & here's the implementation

But would love to know if this is a problem with my implementation of react-autosave or not using React State perfectly or something else?

deadcoder0904 commented 2 years ago

I fixed this! Probably have solution on the branch but don't remember how i solved it :)