Hello! I’ve been trying for about a day now to get my code working properly.
I have an onChange event handler on my component that I want to do two things:
1) handleChange using state (this I have working)
2) run a graphql mutation and submit my new value to the database once the user has stopped typing for around 2 secs, assuming that the new value is different than the old value.
From what I’ve read I need to combine lodash debounce with useMemo so that on every state render a new debounce function is not created. I’ve been trying to do this to no avail.
My debounce either fires on every input change, because it’s changing the dependencies of the useMemo, or I remove the dependencies and the submit function in my useMemo never runs because my values are never updated in the useMemo hook.
Any general advice?
submitted by /u/DARKRonnoc
[link] [comments]