Skip to content

Instantly share code, notes, and snippets.

@greim
Last active October 7, 2018 02:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greim/d4992d969046327af7daf1f610988b2a to your computer and use it in GitHub Desktop.
Save greim/d4992d969046327af7daf1f610988b2a to your computer and use it in GitHub Desktop.
Vacancy Observer Example
/*
* <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>
}
}
@greim
Copy link
Author

greim commented Dec 18, 2017

Vacancy observer pattern described here: https://medium.com/@greim/a-plan-for-data-fetching-a68d171af38

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