Created
December 7, 2020 15:27
-
-
Save foyez/d9c9695537395d74e179fa55d2374312 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
| import React from 'react' | |
| const UserProfile = ({ data }) => { | |
| return ( | |
| <> | |
| <h1>{data.name}</h1> | |
| <h2>{data.email}</h2> | |
| </> | |
| ) | |
| } | |
| export default UserProfile |
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
| import React, { Suspense, useState, useEffect } from 'react' | |
| const UserProfile = React.lazy(() => import('./UserProfile')) | |
| const SuspensefulUserProfile = ({ userId }) => { | |
| const [data, setData] = useState({}) | |
| useEffect(() => { | |
| const fetchData = async () => { | |
| const profile = await fetchUserProfile(userId) | |
| setData(profile) | |
| } | |
| fetchData() | |
| }, [userId]) | |
| return ( | |
| <Suspense fallback={<p>loading...</p>}> | |
| <UserProfile data={data} /> | |
| </Suspense> | |
| ) | |
| } | |
| 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