I am learning React Native and don't have very much experience with this. I am trying to navigate in the App.js file and it gives "TypeError: Cannot read property 'navigate' of undefined" on this line: this.props.navigation.navigate("BlogScreen", {"postId": notification.data.post_id}); I have tried debugging it and also tried a few solutions already asked for a similar question but none seems to work. The difference b/w those questions and mine I think only is that the navigation code is written in "App.js" file in mine. I will be truly grateful for any help I can get.
Some configuration info from package.json:
"@react-navigation/native": "^5.9.3",
"@react-navigation/stack": "^5.14.3",
"axios": "^0.21.1",
"react": "16.13.1",
"react-native": "0.63.4",
"react-redux": "^7.2.2",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
And following is my App.js file
import React, { Component } from 'react'
import AppNavigation from "./app/src/appnavigation/AppNavigation"
import { Provider } from 'react-redux'
import Store from './app/src/redux/store/Store'
import { MenuProvider } from 'react-native-popup-menu'
import FCMServices from "./app/src/utility/PushNotificationHandler"
class App extends Component {
componentDidMount() {
let obj = FCMServices.getInstance(this.FCMServiceCallback);
obj.setNavigationInstance(this.props.navigation);
obj.register(this.onRegister, this.onNotification, this.onOpenNotification)
}
FCMServiceCallback = () => {
console.log("FCMServiceCallback")
}
onRegister = (fcmToken) => {
console.log(fcmToken, "fcmToken")
}
onNotification = (notification) => {
console.log(notification, 'notificationnotificationnotification')
}
onOpenNotification = (notification) => {
this.handleNotificationsClick(notification)
}
handleNotificationsClick = (notification) => {
if (!notification.data) {
return;
} else {
this.props.navigation.navigate("BlogScreen", {"postId": notification.data.post_id});
console.log(notification, 'notificationClicked')
}
}
render() {
return (
<Provider store={Store}>
<MenuProvider>
<AppNavigation />
</MenuProvider>
</Provider>
);
}
}
export default App