T
TanStack4mo ago
wee-brown

Use field value with React Transitions

When I call startTransition(() => field.setValue(...)) inside a form.Field component, it does not seem it triggers what startTransition does. I wanted to use this with React View Transition API, but calling field.setValue inside startTransition did not fire the transition animation. Replacing it with a simple useState hook, it worked well. Is this because TanStack form uses @tanstack/store instead of a plain useState? And if so, is there any way to circumvent this?
2 Replies
constant-blue
constant-blue4mo ago
I'm unfamiliar with the startTransition hook, but perhaps this section of the React reference can help: https://react.dev/reference/react/startTransition#caveats
You can wrap an update into a Transition only if you have access to the set function of that state. If you want to start a Transition in response to some prop or a custom Hook return value, try useDeferredValue instead.
startTransition – React
The library for web and native user interfaces
wee-brown
wee-brownOP4mo ago
@Luca | LeCarbonator Thanks, it worked! Using useDeferredValue inside the inner component triggered the transitions. I should've read the docs thoroughly... Thanks for your help!

Did you find this page helpful?