Created
August 5, 2021 13:42
-
-
Save guvarallo/156e69c0a8132a9d03becf1c6b6d14d5 to your computer and use it in GitHub Desktop.
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
// The 3 problems are: no need to use useEffect, no need to use useState, no need to pass the props around, there is no fallback on Suspense, and fetchUserProfile (assuming it exists, it's imported and returns an object with a list of users) function should be stored in a const. | |
// Here is how I would write it: | |
import { Suspense } from 'react'; | |
const data = fetchUserProfile(); | |
const SuspensefulUserProfile = () => { | |
return ( | |
<Suspense fallback={<h1>Loading...</h1>}> | |
<UserProfileList /> | |
</Suspense> | |
); | |
}; | |
const UserProfile = (user) => { | |
return ( | |
<> | |
<h1>{user.name}</h1> | |
<h2>{user.email}</h2> | |
</> | |
); | |
}; | |
const UserProfileList = () => { | |
const users = data.users.read() | |
return ( | |
<> | |
{users.map(user => ( | |
<UserProfile user={user} /> | |
))} | |
</> | |
) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment