Improve hook that was spamming in dev

This commit is contained in:
James Grugett 2022-09-18 16:57:20 -05:00
parent ae6437442b
commit 17453e5618

View File

@ -105,16 +105,19 @@ export const useMemberGroupIds = (user: User | null | undefined) => {
export function useMemberGroupsSubscription(user: User | null | undefined) {
const cachedGroups = useMemberGroups(user?.id) ?? []
const groupIds = useMemberGroupIds(user)
const [groups, setGroups] = useState(cachedGroups)
const userId = user?.id
useEffect(() => {
if (groupIds) {
if (userId) {
return listenForMemberGroupIds(userId, (groupIds) => {
Promise.all(groupIds.map((id) => getGroup(id))).then((groups) =>
setGroups(filterDefined(groups))
)
})
}
}, [groupIds])
}, [userId])
return groups
}