Skip to content

Instantly share code, notes, and snippets.

@newerton
Created September 15, 2022 17:45
Show Gist options
  • Save newerton/46e387bb97218f8eb3dfe4367f415fca to your computer and use it in GitHub Desktop.
Save newerton/46e387bb97218f8eb3dfe4367f415fca to your computer and use it in GitHub Desktop.
Apply Single responsibility principle (SRP)
const getOnlyActive = (users) => {
const weekAgo = new Date()
weekAgo.setDate(weekAgo.getDate() - 7)
return users.filter(user => !user.isBanned && user.lastActivityAt >= weekAgo)
}
const ActiveUsersList = () => {
const { users } = useUsers()
return (
<ul>
{getOnlyActive(users).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