Challenge 6
by Andrew Nguyen· Module 06 - Lists and Keys

Introduction
Not Attempted
NameProgress
Course outline
Not Read
Module 01 - Diving Into React
Not Attempted
NameProgress
Key Concepts
Not Read
Project: Pet Parade
Not Read
Challenge 1
Not Attempted
Quiz 1
Not Attempted
Module 02 - Components and Props
Not Attempted
NameProgress
Project: Profile Card Creator
Not Read
Key Concepts
Not Read
Challenge 2
Not Attempted
Quiz 2
Not Attempted
Module 03 - State and Effect
Not Attempted
NameProgress
Key Concepts
Not Read
Project: Magic Garden
Not Read
Challenge 3
Not Attempted
Quiz 3
Not Attempted
Module 04 - Conditional Rendering
Not Attempted
NameProgress
Key Concepts
Not Read
Project: Weather Wardrobe
Not Read
Challenge 4
Not Attempted
Quiz 4
Not Attempted
Module 05: Handling Events
Not Attempted
NameProgress
Key Concepts
Not Read
Project: "Interactive Quiz App"
Not Read
Challenge 5
Not Attempted
Quiz 5
Not Attempted
Key Concepts
Project: "Photo Gallery"
Challenge 6
Not Attempted
Quiz 6
Not Attempted
Module 07 - Forms and Validation
Not Attempted
NameProgress
Key Concepts
Not Read
Project: "Registration Form"
Not Read
Challenge 7
Not Read
Quiz 7
Not Attempted
Module 08 - Lifting State Up & Composition vs Inheritance
Not Attempted
NameProgress
Key Concepts
Not Read
Project: "Weather Dashboard"
Not Read
Challenge 8
Not Attempted
Quiz 8
Not Attempted
0 / 470 XP

Overview:

In this challenge, you will enhance the "Photo Gallery" project by adding a button that loads more photos when clicked. This will help you practice handling state updates, managing lists, and interacting with APIs.

Objective:

  • Learn how to dynamically load and append more data to a list.
  • Practice using state and event handling to update the UI.

Instructions for the Interactive Code Block:

Step 1: Create a Button to Load More Photos

Add a button at the bottom of your photo gallery. This button will be used to load more photos.

Step 2: Define the <strong>handleLoadMore</strong> Function

Create a function called <strong>handleLoadMore</strong> that will be triggered when the button is clicked. This function should fetch more photos from the API and append them to the existing list.

Step 3: Append New Photos to the Existing List

In the <strong>handleLoadMore</strong> function, update the state to include the newly fetched photos along with the existing ones.

Step 4: Test the Load More Functionality

Run your application and test the button to ensure it loads more photos each time it's clicked. Make sure the photos are appended to the existing list without duplication.

Next Steps:

  • Add Loading Indicator: Show a loading spinner or message while more photos are being fetched.
  • Error Handling: Handle any errors that occur during the fetch process, such as displaying an error message if the API request fails.

By completing this challenge, you will enhance your Photo Gallery project with dynamic loading functionality, making it more interactive and user-friendly. Enjoy coding and experimenting with your photo gallery!


Step 1 Hint: Place the button inside your component's return statement, below the current list of photos.

// Inside the return statement of PhotoGallery component
&lt;button onClick={handleLoadMore}&gt;Load More Photos&lt;/button&gt;

Step 2 Hint: Use the <strong>fetch</strong> method to get more photos and update the state with the new list of photos.

Discussion

0 comments
Loading editor ...
Remember to be polite and report any undesirable behaviour

Category

Empty

Labels

Discussion has no labels

1 participant

user avatar

Priority

Notifications

You're not receiving notifications from this thread.
Loading...
Ready ...
Course Outline