Challenge: Load User Data from an API
Swipe to show menu
Task
Create a simple user profile that loads user data from an API function using useEffect.
The component must include:
-
A state variable called
user. Its initial value must benull. -
A
useEffecthook.- Call the
fetchUserfunction inside the effect. - Use
.then()to receive the response. - Save the response into the
userstate usingsetUser.
- Call the
-
If
userisnull, render a paragraph (pelement). Its text content must beLoading user.... -
If
userexists, render:- A heading (
h2element) that displays the user name. - A paragraph (
pelement) that displays the user job.
- A heading (
Starter Code
Open the starter project below and complete the missing parts of the component.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Challenge: Load User Data from an API
Task
Create a simple user profile that loads user data from an API function using useEffect.
The component must include:
-
A state variable called
user. Its initial value must benull. -
A
useEffecthook.- Call the
fetchUserfunction inside the effect. - Use
.then()to receive the response. - Save the response into the
userstate usingsetUser.
- Call the
-
If
userisnull, render a paragraph (pelement). Its text content must beLoading user.... -
If
userexists, render:- A heading (
h2element) that displays the user name. - A paragraph (
pelement) that displays the user job.
- A heading (
Starter Code
Open the starter project below and complete the missing parts of the component.
Thanks for your feedback!