Pie Logo
Quiz: Fetching Data
by Tomas Trescak

QuizTest your understanding of the section content.

ContentDetailed description of the section content.

Full Stack Development
Introduction
Generative AI
🍰 Player
💼 Editor
Setup
React Fundamentals
Next.js
Advanced React
Databases
Fetching Data
Quiz: Fetching Data
SQL vs No-SQL Databases
Prisma and ORM
Seeding and Migrations
Search and Pagination
Server Actions
Client-Side Mutations
Validations and Error Handling
Assignment 2.2: Blog - Admin
React Hooks
Authentication and Authorisation
APIs
CI/CD and DevOps
Testing React
Advanced Topics
    Pie Logo
    Quiz: Fetching Data
    by Tomas Trescak

    QuizTest your understanding of the section content.

    ContentDetailed description of the section content.

    Full Stack Development
    Introduction
    Generative AI
    🍰 Player
    💼 Editor
    Setup
    React Fundamentals
    Next.js
    Advanced React
    Databases
    Fetching Data
    Quiz: Fetching Data
    SQL vs No-SQL Databases
    Prisma and ORM
    Seeding and Migrations
    Search and Pagination
    Server Actions
    Client-Side Mutations
    Validations and Error Handling
    Assignment 2.2: Blog - Admin
    React Hooks
    Authentication and Authorisation
    APIs
    CI/CD and DevOps
    Testing React
    Advanced Topics

    Data Fecthing
    by Tomas Trescak· Fetching Data

    QUESTION 1

    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?


    QUESTION 2

    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?


    QUESTION 3

    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?


    QUESTION 4

    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?


    QUESTION 5

    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?


    QUESTION 6

    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?

    This content is only available to registered users.
    Please register at the the home page.

    Data Fecthing
    by Tomas Trescak· Fetching Data

    QUESTION 1

    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?


    QUESTION 2

    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?


    QUESTION 3

    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?


    QUESTION 4

    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?


    QUESTION 5

    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?


    QUESTION 6

    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?

    This content is only available to registered users.
    Please register at the the home page.

    Pie Logo
    Quiz: Fetching Data
    by Tomas Trescak
    Pie Logo
    Quiz: Fetching Data
    by Tomas Trescak
    Full Stack Development
    Introduction
    Generative AI
    🍰 Player
    💼 Editor
    Setup
    React Fundamentals
    Next.js
    Advanced React
    Databases
    Fetching Data
    Quiz: Fetching Data
    SQL vs No-SQL Databases
    Prisma and ORM
    Seeding and Migrations
    Search and Pagination
    Server Actions
    Client-Side Mutations
    Validations and Error Handling
    Assignment 2.2: Blog - Admin
    React Hooks
    Authentication and Authorisation
    APIs
    CI/CD and DevOps
    Testing React
    Advanced Topics
    Full Stack Development
    Introduction
    Generative AI
    🍰 Player
    💼 Editor
    Setup
    React Fundamentals
    Next.js
    Advanced React
    Databases
    Fetching Data
    Quiz: Fetching Data
    SQL vs No-SQL Databases
    Prisma and ORM
    Seeding and Migrations
    Search and Pagination
    Server Actions
    Client-Side Mutations
    Validations and Error Handling
    Assignment 2.2: Blog - Admin
    React Hooks
    Authentication and Authorisation
    APIs
    CI/CD and DevOps
    Testing React
    Advanced Topics