-
Type: Bug
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
?
-
6385
-
Javascript Realm
How frequently does the bug occur?
Always
Description
Hello Everybody
I am bumping into an issue wtih useRealm() and RealmProvider where i get the following error
Error: Realm context not found. Did you call useRealm() within a <RealmProvider/>?
I use a library called @gorhom/bottom-sheet that create a slide up windows. Here is my BottomSheet code :
BottomSheet.js
export default BottomSheetWithRef = React.forwardRef((props, ref) => { const snapPoints = useMemo(() => ["25%", "50%", "75%", "100%"], []); const realm = useRealm() //THis works console.log(realm) //THis works const renderBackdrop = useCallback((props) => { return ( <BottomSheetBackdrop {...props} disappearsOnIndex={-1} appearsOnIndex={0} /> ); }, []); const renderChildren = (data) => { return React.Children.map(props.children, (child, index) => { return React.cloneElement(child, { key: index, bottomSheetData: data }); }); }; return ( <BottomSheetModal backdropComponent={renderBackdrop} ref={ref} index={!Object.is(props.index, undefined) ? props.index : 2} snapPoints={snapPoints} > {({ data }) => { return ( <View style={styles.contentContainer}>{renderChildren(data)}</View> ); }} </BottomSheetModal> ); });
and the render child like :
export default function UpdateDogNameModal(props) { const realm = useRealm() console.log("CHILD REALM IS NOT WORKING") console.log(realm) return ( <View> <Text>I am HERE</Text> </View> ); }
I dont know if I should pass something to the <BottomSheetModal/> children to let the RealmProvider context propagated to the children but right now useRealm() can not be use in the child component
I have created a reproduction of this issue at https://github.com/cyril36/realm_children_issue
git clone https://github.com/cyril36/realm_children_issue.git
cd realm_children_issue
yarn install
yarn android
Can you help me to fix my issue please?
Thank you
Stacktrace & log output
No response
Can you reproduce the bug?
Always
Reproduction Steps
git clone https://github.com/cyril36/realm_children_issue.git
cd realm_children_issue
yarn install
yarn android
Version
"@gorhom/bottom-sheet": "^4.6.0", "@realm/react": "^0.6.2", "expo": "^49.0.8", "expo-dev-client": "~2.4.8", "expo-splash-screen": "~0.20.5", "expo-status-bar": "~1.6.0", "react": "18.2.0", "react-native": "0.72.6", "react-native-gesture-handler": "^2.14.1", "react-native-get-random-values": "~1.9.0", "react-native-paper": "^5.12.1", "react-native-reanimated": "^3.6.1", "react-native-safe-area-context": "^4.8.2", "realm": "^12.5.1"
What services are you using?
Atlas Device Sync
Are you using encryption?
No
Platform OS and version(s)
android
Build environment
flipper
Cocoapods version
No response