You’re building a blog homepage in Next.js that fetches a list of posts from an API (https://api.vercel.app/blog). The page should load quickly and support SEO. Based on the lecture examples, which approach should you use?
https://api.vercel.app/blog
Use useEffect to fetch the data client-side and update state
useEffect
Wrap the fetch in unstable_cache with a revalidate option
unstable_cache
revalidate
Use TanStack Query with a queryKey of ['posts']
queryKey
['posts']
Fetch the data server-side with fetch in the Page component
fetch
Page
Look at this client-side fetching code from the lecture:
'use client'; import { useState, useEffect } from 'react'; export function Posts() { const [posts, setPosts] = useState(null); useEffect(() => { async function fetchPosts() { const res = await fetch('https://api.vercel.app/blog'); const data = await res.json(); setPosts(data); } fetchPosts(); }, []); if (!posts) return <div>Loading...</div>; return ( <ul> {posts.map((post) => ( <li key={post.id}>{post.title}</li> ))} </ul> ); }
What’s true about this code?
It automatically caches the fetched data
The useEffect runs every time the component renders
It displays “Loading…” until the data is fetched
It requires the 'use client' directive
'use client'
Your blog app needs to show a single post page (/blog/[slug]) with its title in the metadata for SEO and pre-render all post routes at build time. Based on the lecture’s getPost example, which functions should reuse the getPost function?
/blog/[slug]
getPost
A client-side useEffect hook
generateMetadata
generateStaticParams
The Page component
You’re optimizing the blog homepage to show both latest and popular posts. The lecture showed sequential vs. parallel fetching. If speed is your priority, which approach works best?
Use Promise.all to fetch both in parallel
Promise.all
Fetch latest posts, then popular posts sequentially
Preload both datasets with a preload function
preload
Use TanStack Query with separate queryKeys for each
You’re using this caching setup from the lecture:
import { unstable_cache } from 'next/cache'; import { db, posts } from '@/lib/db'; const getPosts = unstable_cache( async () => { return await db.select().from(posts); }, ['posts'], { revalidate: 3600, tags: ['posts'] } );
A new post is added to the database. What happens?
You’d need to manually invalidate the cache with the tags
tags
The cache stays stale for up to an hour
The cache updates immediately
The ['posts'] dependency triggers an instant refresh
Your blog API returns a post object with sensitive author data (e.g., author.email). You’ve enabled the taint API. Based on the lecture, what can you do to protect this data?
author.email
Fetch the data client-side with TanStack Query
Use experimental_taintObjectReference on the entire post
experimental_taintObjectReference
Use experimental_taintUniqueValue on author.email
experimental_taintUniqueValue
Cache the post with unstable_cache
This content is only available to registered users.Please register at the the home page.