wise_pomelo_81978
wise_pomelo_81978
TtRPC
Created by Peform on 6/6/2024 in #❓-help
TRPC response data changing to undefined when typing in a form field.
As I mentioned in https://discord.com/channels/867764511159091230/1248003136543522876, it is likely changing to undefined because form.getValues("userId") is changing every time you type and the query cache only has a value for userData for the value that is in the box when you hit submit. You should have your submit button set something in react state and use that for your userId parameter to the query. That way the value will be stable and only change when submit is pressed.
4 replies
TtRPC
Created by Peform on 6/5/2024 in #❓-help
conditionally fetching data with a useQuery
I have a few comments here: 1. For the onSuccess and onError deprecation, I just implemented the suggestions here (https://tkdodo.eu/blog/react-query-error-handling#showing-error-notifications) and it isn't too painful. Also dodges some of the edge cases discussed in that blog post. 2. I agree that the "disable query until something is filled in" use-case can feel a bit awkward. Personally, I wouldn't use RHF for this case (although I understand it might be simplified for this post). If it is just a single field, I'd be more tempted to just useState() for the userId. Especially since it looks like from this code that as soon as the form is submitted once, any further changes to the userid trigger another query? Maybe you can stick with this structure and instead of having state for userLookupEnabled, you can have the userId state.
3 replies