From the course: Master React 19 and Next.js 16 with Hands-On Projects and Real-World Applications
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Implementing pagination for message history
From the course: Master React 19 and Next.js 16 with Hands-On Projects and Real-World Applications
Implementing pagination for message history
Hello, and welcome. In this session, I'll guide you through implementing pagination for your message history. The goal is to move from loading all messages at once to fetching them in smaller, manageable pages. This is a crucial technique for improving performance and user experience in applications with long conversation histories. You will learn how to manage pagination state, fetch older messages on demand, and prepend them to the top of your message list, creating a seamless experience for the user. Now I am introducing the state needed for pagination. I'm adding three new pieces of information. First, we're initializing the offset state variable to zero. This will keep track of how many messages we have already loaded, essentially telling us where to start fetching the next batch from. Second, we're initializing the hasMore state variable to true. This will be true as long as we think there are more messages to fetch from the server, and we'll set it to false once we've reached…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
(Locked)
Introduction to Next.js and project setup15m 30s
-
(Locked)
File-based routing and navigation5m 57s
-
(Locked)
Layouts vs. old custom app component9m 9s
-
(Locked)
Nested layout3m 59s
-
(Locked)
Next.js 16: SSR / ISR / SSG16m 41s
-
(Locked)
Client components and server components9m 54s
-
(Locked)
Passing data from server to client components6m 37s
-
(Locked)
Interleaving server and client components11m 40s
-
(Locked)
Context providers19m 22s
-
(Locked)
Third-party components16m 7s
-
(Locked)
Next.js 16 API routes and fullstack features30m 28s
-
(Locked)
Using a database in Next.js (fullstack data persistence)11m 40s
-
(Locked)
Server-sent events in Next.js (SSE)20m 59s
-
(Locked)
Database relationships (users + messages)17m 42s
-
(Locked)
Building a functional contact form31m 13s
-
(Locked)
Server actions, a powerful Next.js feature11m 27s
-
(Locked)
Add metadata to client and server components9m 24s
-
(Locked)
Build a database viewer19m 30s
-
(Locked)
Build a courses table and seed it with courses data8m 43s
-
(Locked)
Switching from API to database data + image optimization17m 34s
-
(Locked)
Next.js params15m 40s
-
(Locked)
Authentication: Users table creation and seeding15m 47s
-
(Locked)
Authentication: Configuration with JWT26m 35s
-
(Locked)
Authentication: Building an auth-aware navigation bar20m 6s
-
(Locked)
Authentication: Login27m 13s
-
(Locked)
Authentication: Signup28m 9s
-
(Locked)
Authentication: Email verification11m 54s
-
(Locked)
Authentication: Restrict pages6m 51s
-
(Locked)
Authentication: Password reset37m 43s
-
(Locked)
Authentication: Google login16m 52s
-
(Locked)
Authentication: GitHub login5m 54s
-
(Locked)
Adding foreign keys for course in messages9m 34s
-
(Locked)
Add Zod validation to message form9m 4s
-
(Locked)
Restrict chat rooms to a single course13m 46s
-
(Locked)
Using ErrorBoundary and Suspense for safe component rendering10m 28s
-
(Locked)
Pull messages using a server action10m 21s
-
(Locked)
Implementing pagination for message history15m 35s
-
(Locked)
Include user and course when posting a message14m 36s
-
(Locked)
Broadcast new message to connected users12m 17s
-
(Locked)
Optimistically delete a message and notify all users in real time19m 29s
-
(Locked)
Optimistically edit a message and notify all users in real time21m 19s
-
(Locked)
Next.js 16 middleware: Restrict protected route13m 22s
-
(Locked)
Next.js 16 middleware: Restrict admin page7m 33s
-
(Locked)