-
I’m looking to add some sort of auto-save type functionality to a form, where I would use the useMutation hook to send the form data back to the server every 10-15 seconds or so. Has anyone done anything similar to this? I’m wondering what the best way to implement this would be... Would it be best to call the mutation.mutate inside of a setInterval? Any advice/input appreciated! 🙂 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
yep, that sounds fine. have a look at the alternatively, you could |
Beta Was this translation helpful? Give feedback.
yep, that sounds fine. have a look at the
useInterval
hook from Dan: https://overreacted.io/making-setinterval-declarative-with-react-hooks/alternatively, you could
debounce
the value you want to persist and call the mutation in an effect e.g. 1 second after the last change has been made, thus only saving when there is a real change. see thisuseDebounce
hook: https://usehooks.com/useDebounce/