Fork me on GitHub
#react
<
2021-08-15
>
dominicm12:08:44

Googled it because I haven't heard of that before, landed on https://www.amitmerchant.com/the-new-starttransition-api-react-18/. Is it just me or do lots of react people have colourful websites?

dominicm12:08:28

Does useTransition play with suspense? The isPending seems like a separate api for is "is loading?"

lilactown15:08:48

I don't think it's directly related to suspense

lilactown15:08:38

the best resource i've found for these new APIs is the React 18 working group

lilactown15:08:31

based on my experience with it so far, isPending gets set immediately on a render wrapped with startTransition , even if it's not being blocked in any way

lilactown15:08:33

which is different from suspense, which will pause rendering the tree that suspended and notify the nearest suspense boundary, but only if it encounters a suspending component

lilactown15:08:38

in it, they use a CSS transition to only show the pending state if it takes >200ms

lilactown15:08:57

after using it, it makes sense and is very clever

lilactown15:08:31

startTransition signals to React that we are about to do a render that is possibly expensive and we want to opt in to time slicing to keep the app responsive • isPending is set immediately so that we don't have to halt the expensive rendering to render the loading state • then we use CSS transitions or some other way of hiding the loading state until we know the render is taking awhile

lilactown15:08:44

I think the context to a lot of the new APIs in React 18 is that they've decided, rather than have a "Concurrent Mode" that your app either enables or disables, to have the ability to opt in to concurrent rendering for each update. startTransition is one of the ways of doing that

dominicm20:08:50

Oh, and the loading spinner is actually an opacity: 0 float over the content?

dominicm20:08:16

Oh, no. No overlay. They're just switching from pending->done, and not showing a loading spinner.

lilactown20:08:00

they use opacity of the component to show it's in a pending state

lilactown20:08:47

so opacity is normally 100%, they switch to like 30% when isPending with 200ms transition

lilactown21:08:25

for my current side project I switched it to like you're saying. I have a loading indicator always rendered on the page at opacity: 0 and then change it to 100% on isPending with a 200ms transition