Skip to content

Instantly share code, notes, and snippets.

@olabamipetaiwo
Last active September 6, 2021 14:35
Show Gist options
  • Save olabamipetaiwo/578063c90c5812e6477f6b4c2cd2d38a to your computer and use it in GitHub Desktop.
Save olabamipetaiwo/578063c90c5812e6477f6b4c2cd2d38a to your computer and use it in GitHub Desktop.
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