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

componentWillUnmount fired #5

Closed eduardodallmann closed 3 years ago

eduardodallmann commented 3 years ago

Hi, this lib is amazing. I have a question, how autosave behaves when componentWillUnmount fired before debounce time end? If the user quickly fill a input and switches to another screen by menu, autosave should force save. I tried but to no avail.

jollyjerr commented 3 years ago

Hi! Thank you for opening up this issue - I 100% agree that we should force save when components unmount. I'll get to adding that ASAP, or - feel free to open up a PR if you get to it!

jollyjerr commented 3 years ago

This will be released in 0.3.0 🎉

alisayed95 commented 2 years ago

first of all, I would like to thank you for this amazing lib and your elite work. but what if don't need this feature, is there any way to disable it?

jollyjerr commented 2 years ago

Thanks @alisayed95! What use case do you have where you would not like this behavior? 🤔 We can make it optional in the next release, but I can't think of a situation where one would not want the callback to fire on unmount.

alisayed95 commented 2 years ago

so now I'm building sort of reports which has three states "pending", "approved", "drafted". I'm using the lib in the drafted case but when the user click submit button the state should be approved or pending. but what happen that the state is being override in the unmount of the component. I wish my explanation was good enough.

Have nice day mate!

jollyjerr commented 2 years ago

Hey @alisayed95 I added the option saveOnUnmount in 0.4.0 🎉 Let me know if you have any questions

useAutosave({ saveOnUnmount: false });