Last active
September 15, 2022 17:37
-
-
Save newerton/df837a0042b4e98bee5324a3e1f63745 to your computer and use it in GitHub Desktop.
Single responsibility principle (SRP)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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