You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I've started using hooks recently and I am sorry if this issue is not related to this lib.
Could you tell me please is there a way to access updated state values within the debounced function? Let me clarify the problem via comments on the minimal example:
functionApp(){const[value,setValue]=useInputState('')// this just encapsulates passing of the e => e.target.valueconsole.log({valueInRender: value})const[debounced]=useDebouncedCallback(()=>{// `valueInDebounce` will always be late from the `valueInRender` for 1 character// is it possible to overcome somehow without explicit passing of the value?console.log({valueInDebounce: value})},1000)constdecorateSetState=<TextendsFunction>(fn: T)=>(args: any)=>{fn(args)debounced()// passing args.target.value here is undesired}constsetValueDecorated=decorateSetState(setValue)return(<div><inputonChange={setValueDecorated}value={value}/></div>);}
At the moment useDebouncedCallback returns a function, which calls the callback from the render when it was declared. I mean debounced callback calls the function from the previous render. (when value late for 1 char). I'll fix it within 1 or 2 days, and write here when I publish
Hello, I've started using hooks recently and I am sorry if this issue is not related to this lib.
Could you tell me please is there a way to access updated state values within the debounced function? Let me clarify the problem via comments on the minimal example:
You can reproduce the issue in the https://stackblitz.com/edit/react-ts-d9udva
The text was updated successfully, but these errors were encountered: