Created
September 12, 2021 19:56
-
-
Save umair-mirza/15612cb6cb5f22efbcf80f930b059850 to your computer and use it in GitHub Desktop.
Suspense API Challenge solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Suspense, useState } from 'react'; | |
const SuspensefulUserProfile = ({ userId }) => { | |
const resource = fetchUserProfile(userId); | |
return ( | |
<Suspense fallback={<h1>Loading profile...</h1>}> | |
<UserProfile data={resource} /> | |
</Suspense> | |
); | |
}; | |
const UserProfile = ({ data }) => { | |
const name = data.name.read() | |
const email = data.email.read() | |
return ( | |
<> | |
<h1>{name}</h1> | |
<h2>{email}</h2> | |
</> | |
); | |
}; | |
const UserProfileList = () => ( | |
<> | |
<SuspensefulUserProfile userId={1} /> | |
<SuspensefulUserProfile userId={2} /> | |
<SuspensefulUserProfile userId={3} /> | |
</> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment