Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created May 7, 2021 11:56
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sibelius/3ce3937ff59e708027c1d706d20051f1 to your computer and use it in GitHub Desktop.
Suspense Code with Errors
import { Suspense, useState, useEffect } from 'react';
const SuspensefulUserProfile = ({ userId }) => {
const [data, setData] = useState({});
useEffect(() => {
fetchUserProfile(userId).then((profile) => setData(profile));
}, [userId, setData])
return (
<Suspense>
<UserProfile data={data} />
</Suspense>
);
};
const UserProfile = ({ data }) => {
return (
<>
<h1>{data.name}</h1>
<h2>{data.email}</h2>
</>
);
};
const UserProfileList = () => (
<>
<SuspensefulUserProfile userId={1} />
<SuspensefulUserProfile userId={2} />
<SuspensefulUserProfile userId={3} />
</>
);
@juliomerisio
Copy link

I've come up with this solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment