Skip to content

Commit

Permalink
fix(mobile): Refetch queries on app focus
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedBassem committed Mar 30, 2024
1 parent a9c2181 commit 5edfe65
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions apps/mobile/app/dashboard/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import type { AppStateStatus } from "react-native";
import { useEffect } from "react";
import { AppState, Platform } from "react-native";
import { useRouter } from "expo-router";
import { Stack } from "expo-router/stack";
import { useIsLoggedIn } from "@/lib/session";
import { focusManager } from "@tanstack/react-query";

function onAppStateChange(status: AppStateStatus) {
if (Platform.OS !== "web") {
focusManager.setFocused(status === "active");
}
}

export default function Dashboard() {
const router = useRouter();
Expand All @@ -13,6 +22,12 @@ export default function Dashboard() {
}
}, [isLoggedIn]);

useEffect(() => {
const subscription = AppState.addEventListener("change", onAppStateChange);

return () => subscription.remove();
}, []);

return (
<Stack>
<Stack.Screen
Expand Down

0 comments on commit 5edfe65

Please sign in to comment.