fix: fallback to useEffect when no navigation library is available#5
Open
malopezr7 wants to merge 1 commit intocallstackincubator:mainfrom
Open
Conversation
18ad8e7 to
d6416c4
Compare
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.
d6416c4 to
7e7eb94
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Projects that don't use
expo-routeror@react-navigation/nativecrash on import with:This makes
react-native-grabunusable in any project that uses a custom navigation solution.Solution
Instead of throwing, fall back to React's
useEffectas a best-effort substitute. The callback runs on mount instead of on screen focus, which is acceptable for:ReactNativeGrabRootwithoutReactNativeGrabScreenChanges
src/react-native/grab-screen.tsx: Replacethrow new Error(...)with auseEffect-based fallback ingetFocusEffectImpl()Test plan
ReactNativeGrabRootrenders correctly without crash@react-navigation/nativeis installed (existing try/catch still resolves first)