Last active
October 7, 2018 02:11
-
-
Save greim/d4992d969046327af7daf1f610988b2a to your computer and use it in GitHub Desktop.
Vacancy Observer Example
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
/* | |
* <UserProfile/> React component which | |
* uses the vacancy observer pattern. | |
*/ | |
function UserProfile({ | |
userId, // comes from the URL | |
users, // collection of fetched items | |
}) { | |
const user = users[userId]; | |
if (user) { | |
return <div> | |
First Name: { user.first } | |
Last Name: { user.last } | |
... | |
</div> | |
} else { | |
return <div data-vacancy={`users/${userId}`}> | |
Loading... | |
</div> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Vacancy observer pattern described here: https://medium.com/@greim/a-plan-for-data-fetching-a68d171af38