Last active
September 6, 2021 14:35
-
-
Save olabamipetaiwo/578063c90c5812e6477f6b4c2cd2d38a to your computer and use it in GitHub Desktop.
This file contains 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 { React, Suspense, useState, useEffect } from "react"; | |
const SuspensefulUserProfile = ({ userId }) => { | |
const [data, setData] = useState({}); | |
useEffect(() => { | |
fetchUserProfile(userId).then((profile) => setData(profile)); | |
}, [userId]); | |
return ( | |
<Suspense fallback={<h1>Loading ...</h1>}> | |
<UserProfile data={data} /> | |
</Suspense> | |
); | |
}; | |
const UserProfile = ({ data }) => { | |
return ( | |
<> | |
<h1>{data?.name}</h1> | |
<h2>{data?.email}</h2> | |
</> | |
); | |
}; | |
const UserProfileList = () => ( | |
<> | |
<Suspense fallback={<h1>Loading user profile...</h1>}> | |
<SuspensefulUserProfile userId={1} /> | |
</Suspense> | |
<Suspense fallback={<h1>Loading user profile...</h1>}> | |
<SuspensefulUserProfile userId={2} /> | |
</Suspense> | |
<Suspense fallback={<h1>Loading user profile...</h1>}> | |
<SuspensefulUserProfile userId={3} /> | |
</Suspense> | |
</> | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment