From 7e7eb94c629e7bd6e9913d7d55eac25a34543282 Mon Sep 17 00:00:00 2001 From: "manuel.lopez" Date: Wed, 11 Mar 2026 17:06:45 +0100 Subject: [PATCH] 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. --- src/react-native/grab-screen.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/react-native/grab-screen.tsx b/src/react-native/grab-screen.tsx index e5672c0..f99d4ec 100644 --- a/src/react-native/grab-screen.tsx +++ b/src/react-native/grab-screen.tsx @@ -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"; @@ -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();