Skip to content

Instantly share code, notes, and snippets.

@newerton
Created September 15, 2022 17:45
Show Gist options
  • Save newerton/8b96045f8e14b1fb600a18b9497e2ab6 to your computer and use it in GitHub Desktop.
Save newerton/8b96045f8e14b1fb600a18b9497e2ab6 to your computer and use it in GitHub Desktop.
Apply Single responsibility principle (SRP)
const useActiveUsers = () => {
const { users } = useUsers()
const activeUsers = useMemo(() => {
return getOnlyActive(users)
}, [users])
return { activeUsers }
}
const ActiveUsersList = () => {
const { activeUsers } = useActiveUsers()
return (
<ul>
{activeUsers.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