The React docs show that you can defer setState
s by wrapping them in startTransition
from useTransition
.
I'm wondering if any one out there knows how this works and what limitations are there.
In particular my questions are:
startTransition
?dispatch
in startTransition
?isPending
of useTransition
when setStates like redux's dispatch
are considered?The only way to update a state inside a store is to dispatch an action and define a reducer function to perform tasks based on the given actions. Once dispatched, the action goes inside the reducer functions which performs the tasks and return the updated state to the store.
Reducers, as the name suggests, take in two things: previous state and an action. Then they reduce it (read it return) to one entity: the new updated instance of state. So reducers are basically pure JS functions which take in the previous state and an action and return the newly updated state.
can I wrap an update to a context change in startTransition?
Yes.
can I wrap an update to Redux's dispatch in startTransition?
No because Redux (currently) has its own state that's not managed by React. If Redux was using React state as the source of truth, it would have been possible.
what is the logic for isPending of useTransition when setStates like redux's dispatch are considered?
No relation for the reason above.
do I need to worry about tearing as defined by Mark?
Yes, if you use Concurrent Mode, libraries incompatible with it (like Redux currently) can definitely cause tearing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With