The fallback Prop: Spinners and Skeletons
What you'll learn: How to use the fallback prop to provide smooth, user-friendly loading experiences that prevent jarring layout shifts.
When you wrap components in a Suspense boundary, you must provide a fallback prop—it's what users see while waiting for the suspended content to load. This is your opportunity to create a pleasant loading experience rather than showing a blank screen.
Three Common Fallback Strategies
Simple Spinners: The easiest approach is a centered loading spinner. Quick to implement, works anywhere, but can cause layout shifts when content appears.
Skeleton Screens: These are placeholder shapes that mimic the structure of the content about to load. A skeleton of a user profile card, for example, shows gray rectangles where the avatar, name, and bio will appear. This provides visual continuity and feels faster to users.
Preserved Layouts: The most sophisticated approach maintains the overall page structure. If loading a list, you might show the header, filters, and empty list containers immediately, with only the list items themselves suspended. This prevents the entire page from jumping around.
Preventing Layout Shift
The key principle: your fallback should occupy roughly the same screen space as the loaded content. If your article component is 600px tall, your skeleton should be too. This prevents the dreaded "content jump" where everything on screen shifts downward when loading completes.
<Suspense fallback={<ArticleSkeleton />}>
<ArticleContent />
</Suspense>
Think of the fallback as a placeholder that holds the space for incoming content—like a book holding a spot on your shelf while you're reading it elsewhere.
Key Takeaway: The fallback prop accepts any React element; use spinners for simplicity, skeletons for perceived speed, and preserved layouts for professional, shift-free experiences.