Handling Server Side Validation Requests for Username
I am using a svelte query, I have a mutation that calls the backend to check if the username is available debounced on every key stroke. But the responses from the server come out of order. This causes the responses to not reflect the current value. What is the standard approach for this?
2 Replies
metropolitan-bronze•12mo ago
Could you send a code example? In general when I ran into this issue in the past the culprit was that instead of having the query retrigger by changing the query key, I was trying to run the debounce function as the queryFn. If that is your case I'd recommend the query rerunning solely based on the key changes such as:
['search', username]
.
Also, double check to make sure the debounced function is running correctly where it isn't just delaying the inputs and sending each change versus only sending the latest change within the debounce time allowance. I've ran into this issue with debounce within react where I needed to use a memoization tacticdeep-jadeOP•12mo ago
oooh. Yes you are right I am triggering the mutation manually rather than using query key @knorv I'll fix that and it should work.