Pie Logo
Quiz: Lists
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
JSX and Components
Props
Assignment 1.2: Front End
CSS Styles
useState and Hooks
Conditional Rendering
Lists
Exercise: Lists
Quiz: Lists
Forms and Events
Storybook
Assignment 1.3: Bonus - Backend
Leaderboards
Next.js
Advanced React
Databases
React Hooks
Authentication and Authorisation
APIs
CI/CD and DevOps
Testing React
Advanced Topics
    Pie Logo
    Quiz: Lists
    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
    JSX and Components
    Props
    Assignment 1.2: Front End
    CSS Styles
    useState and Hooks
    Conditional Rendering
    Lists
    Exercise: Lists
    Quiz: Lists
    Forms and Events
    Storybook
    Assignment 1.3: Bonus - Backend
    Leaderboards
    Next.js
    Advanced React
    Databases
    React Hooks
    Authentication and Authorisation
    APIs
    CI/CD and DevOps
    Testing React
    Advanced Topics

    Lists
    by Tomas Trescak· Lists

    QUESTION 1

    You’re building a to-do list app in React. You write the following code to render the list, but the console shows a warning: "Each child in a list should have a unique 'key' prop."

    const todos = ["Buy milk", "Call mom", "Finish homework"];
    function ToDoList() {
      return (
        <ul>
          {todos.map((todo) => <li>{todo}</li>)}
        </ul>
      );
    }
    

    What can you do to fix this warning?


    QUESTION 2

    Consider this code where a list of articles is displayed:

    const articles = [
      { id: 1, title: "React Basics" },
      { id: 2, title: "Advanced JSX" }
    ];
    function ArticleList({ articles }) {
      return (
        <ul>
          {articles.map((article, index) => <li key={index}>{article.title}</li>)}
        </ul>
      );
    }
    

    A user adds a new article { id: 3, title: "Hooks Intro" } at the beginning of the list. What might go wrong?


    QUESTION 3

    You’re tasked with improving this code to follow best practices:

    const tasks = [
      { id: "t1", desc: "Task 1" },
      { id: "t2", desc: "Task 2" }
    ];
    function TaskList({ tasks }) {
      return (
        <ul>
          {tasks.map((task, index) => <li key={index}>{task.desc}</li>)}
        </ul>
      );
    }
    

    Which of the following changes align with React best practices?


    QUESTION 4

    You encounter this code in a project:

    function ItemList({ items }) {
      return (
        <>
          {items.map((item) => <span>{item.name}</span>)}
        </>
      );
    }
    

    Why does this code fail, and how can you fix it?


    QUESTION 5

    Imagine you’re debugging this app:

    const initialBooks = [
      { id: 1, title: "Book A" },
      { id: 2, title: "Book B" }
    ];
    function BookList({ books }) {
      if (!books.length) {
        return <p>No books available.</p>;
      }
      return (
        <ul>
          {books.map((book, index) => <li key={index}>{book.title}</li>)}
        </ul>
      );
    }
    function App() {
      return <BookList books={initialBooks} />;
    }
    

    A user deletes "Book A" (id: 1), leaving only "Book B" (id: 2). What’s the best way to improve this code based on the result?

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

    Lists
    by Tomas Trescak· Lists

    QUESTION 1

    You’re building a to-do list app in React. You write the following code to render the list, but the console shows a warning: "Each child in a list should have a unique 'key' prop."

    const todos = ["Buy milk", "Call mom", "Finish homework"];
    function ToDoList() {
      return (
        <ul>
          {todos.map((todo) => <li>{todo}</li>)}
        </ul>
      );
    }
    

    What can you do to fix this warning?


    QUESTION 2

    Consider this code where a list of articles is displayed:

    const articles = [
      { id: 1, title: "React Basics" },
      { id: 2, title: "Advanced JSX" }
    ];
    function ArticleList({ articles }) {
      return (
        <ul>
          {articles.map((article, index) => <li key={index}>{article.title}</li>)}
        </ul>
      );
    }
    

    A user adds a new article { id: 3, title: "Hooks Intro" } at the beginning of the list. What might go wrong?


    QUESTION 3

    You’re tasked with improving this code to follow best practices:

    const tasks = [
      { id: "t1", desc: "Task 1" },
      { id: "t2", desc: "Task 2" }
    ];
    function TaskList({ tasks }) {
      return (
        <ul>
          {tasks.map((task, index) => <li key={index}>{task.desc}</li>)}
        </ul>
      );
    }
    

    Which of the following changes align with React best practices?


    QUESTION 4

    You encounter this code in a project:

    function ItemList({ items }) {
      return (
        <>
          {items.map((item) => <span>{item.name}</span>)}
        </>
      );
    }
    

    Why does this code fail, and how can you fix it?


    QUESTION 5

    Imagine you’re debugging this app:

    const initialBooks = [
      { id: 1, title: "Book A" },
      { id: 2, title: "Book B" }
    ];
    function BookList({ books }) {
      if (!books.length) {
        return <p>No books available.</p>;
      }
      return (
        <ul>
          {books.map((book, index) => <li key={index}>{book.title}</li>)}
        </ul>
      );
    }
    function App() {
      return <BookList books={initialBooks} />;
    }
    

    A user deletes "Book A" (id: 1), leaving only "Book B" (id: 2). What’s the best way to improve this code based on the result?

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

    Pie Logo
    Quiz: Lists
    by Tomas Trescak
    Pie Logo
    Quiz: Lists
    by Tomas Trescak
    Full Stack Development
    Introduction
    Generative AI
    🍰 Player
    💼 Editor
    Setup
    React Fundamentals
    JSX and Components
    Props
    Assignment 1.2: Front End
    CSS Styles
    useState and Hooks
    Conditional Rendering
    Lists
    Exercise: Lists
    Quiz: Lists
    Forms and Events
    Storybook
    Assignment 1.3: Bonus - Backend
    Leaderboards
    Next.js
    Advanced React
    Databases
    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
    JSX and Components
    Props
    Assignment 1.2: Front End
    CSS Styles
    useState and Hooks
    Conditional Rendering
    Lists
    Exercise: Lists
    Quiz: Lists
    Forms and Events
    Storybook
    Assignment 1.3: Bonus - Backend
    Leaderboards
    Next.js
    Advanced React
    Databases
    React Hooks
    Authentication and Authorisation
    APIs
    CI/CD and DevOps
    Testing React
    Advanced Topics