Created
November 17, 2021 21:21
-
-
Save forrestwilkins/f3ef75e89bc24b3644bdbf8744112e6f 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 { Suspense, useState, useEffect } from "react"; | |
const fetchUserProfile = (userId) => { | |
return new Promise((resolve) => { | |
resolve({ | |
name: `Forrest ${userId}`, | |
email: `forrest${userId}@gmail.com`, | |
}); | |
}); | |
}; | |
const UserProfile = ({ data }) => { | |
return ( | |
<> | |
<h1>{data.name}</h1> | |
<h2>{data.email}</h2> | |
</> | |
); | |
}; | |
const SuspensefulUserProfile = ({ userId }) => { | |
const [data, setData] = useState({}); | |
useEffect(() => { | |
fetchUserProfile(userId).then((profile) => setData(profile)); | |
}, [userId, setData]); | |
return ( | |
<Suspense> | |
<UserProfile data={data} /> | |
</Suspense> | |
); | |
}; | |
const UserProfileList = () => ( | |
<> | |
<SuspensefulUserProfile userId={1} /> | |
<SuspensefulUserProfile userId={2} /> | |
<SuspensefulUserProfile userId={3} /> | |
</> | |
); | |
export default UserProfileList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment