Loading states for data
📖 Scenario: You are building a simple Next.js app that fetches user data from an API. To improve user experience, you want to show a loading message while the data is being fetched.
🎯 Goal: Create a Next.js functional component that fetches user data and shows a loading message until the data is ready.
📋 What You'll Learn
Create a React functional component named
UserList.Use
useState to hold the user data and loading state.Use
useEffect to fetch data from https://jsonplaceholder.typicode.com/users when the component mounts.Show a
Loading... message while fetching data.Display the list of user names after data is loaded.
💡 Why This Matters
🌍 Real World
Loading states are common in web apps to inform users that data is being fetched, improving user experience.
💼 Career
Understanding loading states and data fetching is essential for frontend developers working with React and Next.js.
Progress0 / 4 steps