+
Fullstack developper @ Cap Collectif
Without React Concurrent
All this stuff is blocking. When React renders, it can not interrupt it's work
With React Concurrent
With this approach, React can prioritize updates and avoid stuterrings
It is a mechanism for data fetching libraries
It is not a data fetching implementation
It does not couple data fetching to the view layer
You may expect some BCs
The Suspense Component
<Suspense fallback={<Loader />}>
<PostList />
</Suspense>
Display a <Loader/> when <PostList/> is fetching data
The SuspenseList Component
<SuspenseList revealOrder="forwards" tail="collapsed">
<Suspense fallback={'Loading...'}>
<ProfilePicture id={1} />
</Suspense>
<Suspense fallback={'Loading...'}>
<ProfilePicture id={2} />
</Suspense>
<Suspense fallback={'Loading...'}>
<ProfilePicture id={3} />
</Suspense>
...
</SuspenseList>
Orchestrate loadings of <ProfilePicture/> components so that they appear from top to bottom
The useTransition hook
const SUSPENSE_CONFIG = {timeoutMs: 200 };
function App() {
const [resource, setResource] = useState(initialResource);
const [startTransition, isPending] = useTransition(SUSPENSE_CONFIG);
return (
<>
<button
disabled={isPending}
onClick={() => {
startTransition(() => {
const nextUserId = getNextId(resource.userId);
setResource(fetchProfileData(nextUserId));
});
}}
>
Next
</button>
{isPending ? " Loading..." : null}
<Suspense fallback={<Spinner />}>
<ProfilePage resource={resource} />
</Suspense>
</>
);
}
Allows to tells React that some user-action will transition to a new state that will cause the component to suspend. This can only be done thanks to Concurrent Mode
We are not all Facebook