I cannot use react navigator in the onRead function
See original GitHub issueWhat’s happening?
I am trying to navigate the user to a different screen when onRead is successful. But throws an error saying TypeError: undefined is not an object (evaluating 'navigation.navigate')
How can it be reproduced?
Try to use react-navigation in the function of onRead to reproduce this error.
Build details?
I am using the latest version of react-native-qrcode-scanner on a physical device running android.
My code
import React from 'react';
import QRCodeScanner from 'react-native-qrcode-scanner';
import {RNCamera} from 'react-native-camera';
import {Text, View} from 'react-native';
import {globalStyles} from '../styles/global';
import {useDispatch} from 'react-redux';
import {startUsing} from '../redux/actions/deskActions';
const Start = ({navigation}) => {
const dispatch = useDispatch();
const onSuccess = e => {
// dispatch(startUsing(e.data));
console.log(e.data);
navigation.navigate('Home');
scanner.reactivate();
};
return (
<View style={globalStyles.container}>
<View style={{...globalStyles.center, marginVertical: 50}}>
<Text style={{...globalStyles.titleText, marginBottom: 20}}>
Scan the QR Code to start session
</Text>
<QRCodeScanner
reactivate={true}
reactivateTimeout={2000}
showMarker={true}
ref={node => {
scanner = node;
}}
onRead={onSuccess}
flashMode={RNCamera.Constants.FlashMode.auto}
cameraStyle={{width: '80%', marginHorizontal: 20, height: '100%'}}
/>
</View>
</View>
);
};
export default Start;
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top Results From Across the Web
onReady={() => {}} callback called before navigationRef is ...
I am following the react native screen navigation documentation and passing a callback to onReady to set the routeNameRef.current to the ...
Read more >Cannot read property 'navigate' of undefined React Native - ...
I've solved the problem using useNavigation function: import { View, Button } from 'react-native'; import { useNavigation } from ...
Read more >NavigationContainer
The NavigationContainer is responsible for managing your app state and linking your top-level navigator to the app environment.
Read more >React Native
Sentry's React Native SDK enables automatic reporting of errors and exceptions, and identifies performance issues in your application. The React Native SDK ...
Read more >NavigationContainer | React Navigation - Netlify
It's also possible to attach a ref to the container to get access to various helper methods, for example, dispatch navigation actions. Example:...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yay! This is working as expected. Thanks a lot for helping. 😄
Glad that help you! Happy Coding @manan2501 !