Skip to content

Instantly share code, notes, and snippets.

@newerton
Created September 15, 2022 17:43
Show Gist options
  • Save newerton/3b01f4d790cee5698e493904f45c6527 to your computer and use it in GitHub Desktop.
Save newerton/3b01f4d790cee5698e493904f45c6527 to your computer and use it in GitHub Desktop.
Apply Single responsibility principle (SRP)
onst UserItem = ({ user }) => {
return (
<li>
<img src={user.avatarUrl} />
<p>{user.fullName}</p>
<small>{user.role}</small>
</li>
)
}
const ActiveUsersList = () => {
const { users } = useUsers()
const weekAgo = new Date()
weekAgo.setDate(weekAgo.getDate() - 7)
return (
<ul>
{users.filter(user => !user.isBanned && user.lastActivityAt >= weekAgo).map(user =>
<UserItem key={user.id} user={user} />
)}
</ul>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment