msg
This commit is contained in:
@@ -12,10 +12,15 @@ export function useRooms() {
|
||||
// activeRoomId === null => all rooms combined via /events
|
||||
export function useEvents(activeRoomId: number | null, from?: string, to?: string) {
|
||||
const key = activeRoomId === null ? ["events", from, to] : ["room-events", activeRoomId, from, to]
|
||||
const { data, error, isLoading, mutate } = useSWR(key, () =>
|
||||
activeRoomId === null
|
||||
? api.getUserEvents(from, to)
|
||||
: api.getRoomEvents(activeRoomId, from, to),
|
||||
const { data, error, isLoading, mutate } = useSWR(
|
||||
key,
|
||||
() =>
|
||||
activeRoomId === null
|
||||
? api.getUserEvents(from, to)
|
||||
: api.getRoomEvents(activeRoomId, from, to),
|
||||
// Keep showing the previous week/room's events while the new key loads,
|
||||
// instead of flashing an empty/loading state on every switch.
|
||||
{ keepPreviousData: true },
|
||||
)
|
||||
return { events: data ?? [], error, isLoading, mutate }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user