Using a suspending query for initial form data #5763
-
Hi, I am trying to figure out the best practice for using tanstack-query + suspend + react-hook-form. Here is the problem. Given code like: export const MyPage: React.FC = () => {
const { data } = useQuery(myFetchFn, { query: { suspense: true, staleTime: 0, cacheTime: 0 } });
const myForm = useForm({
defaultValues: data, // This only reads the value once
});
// etc...
} On first load this works great. The page suspends before the However, if you navigate away from this page and back, the query will re-fire as expected, but it doesn't suspend. This causes the form to load the old Both of these related discussions explain that there's no way to force a suspend:
How do you recommend handling this case? Ty! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
you can use the reactive
|
Beta Was this translation helpful? Give feedback.
you can use the reactive
values
api from react-hook-form:https://react-hook-form.com/docs/useform#values