Patterns for startTransition #100
tesseralis
started this conversation in
Q&A
Replies: 1 comment 8 replies
-
It's a bit confusing that we explained function Form() {
const [state, setState] = useState({ value: "hello" })
const deferredState = useDeferredValue(state)
// ... Here there's no Is this helpful? We're still working out how to explain the primitives. There's definitely some overlap there. |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
One major use case for
startTransition
is to update an input instantaneously while things that depend on that input's value are possibly delayed:In this case, the initial
value
passed in is only used to initialize the input, which is then controlled internally by the component. I believe this is already a common use case, withdebounce
instead ofstartTransition
.However, if the
value
can change through other means, such as a reset button on a form, this pattern is broken:In the example, the reset button does not work: even though
state.value
has been updated,<TransInput />
does not update the value because thevalue
prop is discarded after the initial render.While this example is simplistic, and there's still questions on where
startTransition
should be used, I imagine this is a common pattern that can arise for its use case: whenever there is state that needs to be immediately updated in one part of the UI but may be deferred in others, the same state must be kept in two places and be "synced" in some way. Has the React team dealt with this situation? If so how have they resolved it? If not, is there an alternate pattern or way of encoding the same desired behavior?Beta Was this translation helpful? Give feedback.
All reactions