Skip to content

Instantly share code, notes, and snippets.

@newerton
Last active September 15, 2022 17:37
Show Gist options
  • Save newerton/df837a0042b4e98bee5324a3e1f63745 to your computer and use it in GitHub Desktop.
Save newerton/df837a0042b4e98bee5324a3e1f63745 to your computer and use it in GitHub Desktop.
Single responsibility principle (SRP)
const ActiveUsersList = () => {
const [users, setUsers] = useState([])
useEffect(() => {
const loadUsers = async () => {
const response = await fetch('/some-api')
const data = await response.json()
setUsers(data)
}
loadUsers()
}, [])
const weekAgo = new Date();
weekAgo.setDate(weekAgo.getDate() - 7);
return (
<ul>
{users.filter(user => !user.isBanned && user.lastActivityAt >= weekAgo).map(user =>
<li key={user.id}>
<img src={user.avatarUrl} />
<p>{user.fullName}</p>
<small>{user.role}</small>
</li>
)}
</ul>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment