Last active
July 4, 2022 08:06
-
-
Save koss-lebedev/7e2a36e744241e3b08ea0ecbdf103f19 to your computer and use it in GitHub Desktop.
This file contains 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 useUsers = () => { | |
const [users, setUsers] = useState([]) | |
useEffect(() => { | |
const loadUsers = async () => { | |
const response = await fetch('/some-api') | |
const data = await response.json() | |
setUsers(data) | |
} | |
loadUsers() | |
}, []) | |
return { users } | |
} | |
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 => | |
<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