Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What kinds of state updates can we defer with `useTransition`?

Tags:

reactjs

The React docs show that you can defer setStates 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:

  • can I wrap an update to a context change in startTransition?
  • can I wrap an update to Redux's dispatch in startTransition?
  • what is the logic for isPending of useTransition when setStates like redux's dispatch are considered?
  • do I need to worry about tearing as defined by Mark?
like image 338
Rico Kahler Avatar asked Oct 29 '19 16:10

Rico Kahler


People also ask

Where can state can be updated in Redux?

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.

What is reducer in react?

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.


1 Answers

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.

like image 147
Dan Abramov Avatar answered Oct 11 '22 05:10

Dan Abramov