Skip to content

Commit 7e7eb94

Browse files
manuel.lopezmanuel.lopez
authored andcommitted
fix: fallback to useEffect when no navigation library is available
Projects using custom navigators that don't ship expo-router or @react-navigation/native crash on import with "No useFocusEffect implementation found". Instead of throwing, fall back to useEffect as a best-effort substitute.
1 parent c2a778c commit 7e7eb94

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/react-native/grab-screen.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useRef } from "react";
1+
import { useCallback, useEffect, useRef } from "react";
22
import { View, type ViewProps } from "react-native";
33
import { setFocusedScreenRef } from "./containers";
44

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

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

2128
const useFocusEffect = getFocusEffectImpl();

0 commit comments

Comments
 (0)