Skip to content

Instantly share code, notes, and snippets.

@viniciusdacal
Last active February 9, 2018 12:57
Show Gist options
  • Save viniciusdacal/bef1bc3b6f5ee9ce15e017af0270f5d8 to your computer and use it in GitHub Desktop.
Save viniciusdacal/bef1bc3b6f5ee9ce15e017af0270f5d8 to your computer and use it in GitHub Desktop.
const UserList = ({ isLoading, results, error }) => {
const shouldDisplayLoader = !error && isLoading;
const shouldDisplayNoResults = !error && !isLoading && !results.length;
const shouldDisplayList = !error && !isLoading && results.length > 0;
return (
<div>
<div>
<h1>Users</h1>
<a href="/users/create">New User</a>
</div>
<div>
{error && <span>Something is not right!</span>}
{shouldDisplayLoader && <span>Loading...</span>}
{shouldDisplayNoResults && (
<span>No Results Found</span>
)}
{shouldDisplayList && (
<ul>
{result.map((user) => (
<li key={user.id}>{user.name}</li>
))}
</ul>
)}
</div>
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment