Skip to content
Discussion options

You must be logged in to vote

You don't need useEffect for this: a field can have listeners, which run on the change event itself, and they support debouncing. From there you call TanStack Query imperatively with queryClient.fetchQuery (so lookups are still cached) and write the other fields with form.setFieldValue.

function CustomerForm() {
  const queryClient = useQueryClient()
  const form = useForm({
    defaultValues: { postalCode: '', street: '', city: '' },
  })

  return (
    <form>
      <form.Field
        name="postalCode"
        listeners={{
          onChangeDebounceMs: 400,
          onChange: async ({ value, fieldApi }) => {
            const code = value.replace(/\D/g, '')
            if (code.length !…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by GustavoOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants