,

Implementing Skeleton Loading for Search and Pagination in NextJs 13 Movie App

Posted by






Loading Skeleton for Search & Pagination in NextJs 13 Movie App

Loading Skeleton for Search & Pagination in NextJs 13 Movie App

When creating a movie app using NextJs 13, you may encounter a need to improve the user experience by adding loading skeletons for search and pagination. Loading skeletons provide a placeholder for content while the actual data is being loaded, thus preventing a jumpy or empty UI during the loading process.

To implement loading skeletons for search and pagination in your NextJs 13 movie app, you can use HTML and CSS to create the visual representation of the skeleton. Here’s a step-by-step guide on how to do it:

Step 1: Create HTML Structure

First, create the HTML structure for the loading skeleton. You can use

elements with specific classes to represent the content that will be loaded. For example, for the search section, you can create a

with a class “search-skeleton”:


<div class="search-skeleton"></div>

Similarly, for the pagination section, you can create a

with a class “pagination-skeleton”:


<div class="pagination-skeleton"></div>

Step 2: Style the Loading Skeleton

Next, use CSS to style the loading skeleton. You can use animations or background patterns to give the illusion of content being loaded. Here’s an example of CSS for the search and pagination skeletons:


.search-skeleton {
height: 20px;
background: #f2f2f2;
animation: loading 1s infinite;
}

.pagination-skeleton {
height: 10px;
background: #f2f2f2;
animation: loading 1s infinite;
}

@keyframes loading {
0% { background: #f2f2f2; }
50% { background: #e6e6e6; }
100% { background: #f2f2f2; }
}

Step 3: Use the Loading Skeleton in NextJs 13 Movie App

Finally, integrate the loading skeleton HTML and CSS into your NextJs 13 movie app. You can conditionally render the loading skeleton while the data is being fetched, and then replace it with the actual content once the data is loaded.

By following these steps, you can improve the user experience of your NextJs 13 movie app by providing a smooth loading transition for search and pagination features.


0 0 votes
Article Rating
16 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
ekimCodes
1 year ago

Await method is cool !can we promise.all 2 different promises and await both of them in await function ?

ekimCodes
1 year ago

Thank you so much for the information thats really useful. Can i ask a question here, since we are "disabling" client cache in browser by adding key, it will not affect the server cache right if we send request with native fetch api and cache set to "force-cache" ?

Rsham Hz
1 year ago

you save my life hamed😍😍😍😍😍after one week search about this in whole of internet much thanks❤

Liu He
1 year ago

So this is great, but when the images come in, you can see there is a fraction of second of gray background before the images appear, but the text is instant. Is there a way to avoid that so the image and text appear at the same time? I guess what I mean is like how Unsplash shows a blur image while loading.

Tomáš Sabol
1 year ago

isn't this solution going to introduce hydration errors?

Praful Karmur
1 year ago

wow it's really to help full i spend hour's and hours but you give solution within 10 minutes thank's a lot , you make video on real problems of work issue that's really very helpful to us

Deepanshu Verma
1 year ago

Its working in Devlopment mode but when prodcution fallback is not showing

Mehdi Yahyavi
1 year ago

hi. your solution is great. but if we have to use react hooks like useState, to handle client change, like change view of movie from column style to row style, we loose async in page and should to use client tag top of page.tsx file.
this is my problem in real project that client can change view.

Adil Chehabi
1 year ago

Thanks a lot Hamed, I struggled with that and gave up after hours of searching and reading the doc.
Your way of explaining complex concepts is the best I've ever seen, in every tutorial I found you answering all the questions that are in my head 👍.

Mehdi Fada-yi
1 year ago

merci ke enghad khobi mishe rajebe kar ba headlessUi ham video besazi

Eliuddy Neftali
1 year ago

Amazing Bro 🔥🔥

Albert Ilagan
1 year ago

Great vid, how about using the searchParams as `key`? instead of `uuid` or math.random?

Mack Rafael
1 year ago

Great video, thanks a lot!

Germain
1 year ago

Love your videos! Learned a lot from your section on router caching. Would be amazing if you could make one video summarizing all of the Caching behavior in Next.js 13.4+ as I believe that is the single biggest headache in the new Next.js

NOTHING
1 year ago

very well tutorial, thanks a lot ❤

Varun Aggarwal
1 year ago

Hey, really informative. One question though, lets say i have 3 api calls on my page component. I want one call to be revalidated after every 45 seconds and want to pass the result of this call to 2 other calls on this page. For these 2 calls i want to disable caching and as i am using next.js extended fetch api. I set cache:no-store. Now if i switch between pages, i see my data is stale. I will try setting key attribute, but if i set key attribute does caching works for my first api call?