Skip to content

Instantly share code, notes, and snippets.

@umair-mirza
Created September 12, 2021 19:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umair-mirza/15612cb6cb5f22efbcf80f930b059850 to your computer and use it in GitHub Desktop.
Save umair-mirza/15612cb6cb5f22efbcf80f930b059850 to your computer and use it in GitHub Desktop.
Suspense API Challenge solution
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