Skip to content

fix: fallback to useEffect when no navigation library is available#5

Open
malopezr7 wants to merge 1 commit intocallstackincubator:mainfrom
malopezr7:fix/fallback-usefocuseffect-custom-navigators
Open

fix: fallback to useEffect when no navigation library is available#5
malopezr7 wants to merge 1 commit intocallstackincubator:mainfrom
malopezr7:fix/fallback-usefocuseffect-custom-navigators

Conversation

@malopezr7
Copy link

@malopezr7 malopezr7 commented Mar 11, 2026

Problem

Projects that don't use expo-router or @react-navigation/native crash on import with:

Error: No useFocusEffect implementation found

This makes react-native-grab unusable in any project that uses a custom navigation solution.

Solution

Instead of throwing, fall back to React's useEffect as a best-effort substitute. The callback runs on mount instead of on screen focus, which is acceptable for:

  • Single-screen setups
  • Custom navigators without a focus/blur lifecycle
  • Projects that only use ReactNativeGrabRoot without ReactNativeGrabScreen

Changes

  • src/react-native/grab-screen.tsx: Replace throw new Error(...) with a useEffect-based fallback in getFocusEffectImpl()

Test plan

  • Verified in a React Native 0.83 project using a custom router (no expo-router or react-navigation)
  • ReactNativeGrabRoot renders correctly without crash
  • No regression when @react-navigation/native is installed (existing try/catch still resolves first)

@malopezr7 malopezr7 force-pushed the fix/fallback-usefocuseffect-custom-navigators branch 2 times, most recently from 18ad8e7 to d6416c4 Compare March 11, 2026 16:11
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.
@malopezr7 malopezr7 force-pushed the fix/fallback-usefocuseffect-custom-navigators branch from d6416c4 to 7e7eb94 Compare March 11, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant