Skip to content

Instantly share code, notes, and snippets.

@guvarallo
Created August 5, 2021 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guvarallo/156e69c0a8132a9d03becf1c6b6d14d5 to your computer and use it in GitHub Desktop.
Save guvarallo/156e69c0a8132a9d03becf1c6b6d14d5 to your computer and use it in GitHub Desktop.
// 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