Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/react-native/grab-screen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useRef } from "react";
import { useCallback, useEffect, useRef } from "react";
import { View, type ViewProps } from "react-native";
import { setFocusedScreenRef } from "./containers";

Expand All @@ -15,7 +15,14 @@ const getFocusEffectImpl = (): ((cb: () => void) => void) => {
// Nothing we can do about it, it's not installed in the project.
}

throw new Error("No useFocusEffect implementation found");
// No supported router found — fall back to useEffect
return (cb: () => void) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
useEffect(() => {
const cleanup = cb();
return typeof cleanup === "function" ? cleanup : undefined;
}, [cb]);
};
};

const useFocusEffect = getFocusEffectImpl();
Expand Down