- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
undefined is not an object problem #1569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Is the component the |
@matthamil const SimpleApp = StackNavigator({ |
Can you post your full code? |
I meet the same problem, how do you fix it? |
@IcyCC Can you post your code? |
I write these in index.android.js
And when I write in MovieCard.js
the error happen . And I put const { navigate } = this.props.navigation; in other component there no error |
@IcyCC Do you have a repo with the entire source code? It's hard to tell from what you posted to see where the bug is. It could be an issue with incorrect import names. |
like this ?https://github.com/IcyCC/Ticket-app |
@IcyCC You are trying to render a
The |
Thank you !!! I get it!You did me a big favor! |
I'm having the same issue with the sample code from: https://reactnavigation.org/docs/intro#Introducing-Stack-Navigator I basically copied and pasted the code into my editor (with the small difference that here I export the default HomeScreen and removed the AppRegistry). When I open it on Expo, I get the error: "undefined is not an object (evaluating 'this.props.navigation.navigate)'". Any help? It's a bit frustrating that the example from the documentation does not work :) Thank you in advance! import React from 'react'; class ChatScreen extends React.Component { export default class HomeScreen extends React.Component { render() { } const TheApp = StackNavigator({ |
Getting the same error with the example from the documentation here: https://facebook.github.io/react-native/docs/navigation.html `import React from 'react'; import { export default class HomeScreen extends React.Component { class ProfileScreen extends React.Component {
} const App = StackNavigator({ Any idea what might be wrong? I will be happy to send a PR to update the documentation if we can manage to understand the problem here. |
It looks like you are exporting your |
Thanks @matthamil ! Is there any up-to-date documentation on that? |
It is documented here: https://reactnavigation.org/docs/navigators/navigation-prop#Screen-Navigation-Prop, although this isn't the first time someone has encountered this problem. If you know a way to word the documentation better to prevent this from happening for other users, feel free to open a PR to help everyone out :) |
Sure thing! It's a bit frustrating that the Hello World example in the Getting Started does not work :) Thank you so much! |
@matthamil Having the same problem - can you give more explicit instructions on how to pass navigation as a prop? Thanks! :) |
@pmuldoon86 I managed to set my navigation correctly after watching this screencast: It shows some basic tab + stack navigation hints that's exactly what I was looking for. If you're writing a normal screen, you have to "export" it in the end of the code to make sure it can be navigated to: import React, {Component} from 'react'; import { ScrollView, Text } from 'react-native'; `import React, {Component} from 'react'; import { ScrollView, Text } from 'react-native'; class Tools extends Component { render() { export default Tools; |
@pmuldoon86 Within your render() {
return <MyOtherComponent navigation={this.props.navigation}/>
} This is no different from how you would pass props down in React because that's exactly what it is :) |
I'm going to close this issue for now. This seems to be a fairly common issue, so I will see how the documentation describes how I am assuming that one of these solutions resolves your problem @payamka. If your issue is not resolved, please comment or open another issue. |
Thanks! |
If using Expo, you need something like this: |
Hi Matt, I am hoping you can help me. I have been working on the same problem the past three days, trying everything. It seems like you have been able to help people solve this problem in the past. Somehow "navigation" is not being passed to my "navigated" components. I have tried putting the StackNavigator code everywhere - own file, like it is now, in App.js, in the files of one of my components. Nothing has worked. Here is a link to my repository.. https://github.com/rscharfer/mobileflashcards Do you think you can help? The StackNavigator code is in stack.js currently. |
I was having the same issue. It was solved by changing |
Never use stack navigation in 'index.android.js' file Error: Try this Code your Navigation will work perfectly type Props = {}; // MainActivity.js class MainActivity extends Component { FunctionToOpenSecondActivity = () => {this.props.navigation.navigate('Second');}
} |
Undefined is not an object error message occuring in line |
Hi
I want to test codes in this page: https://reactnavigation.org/docs/intro
And I get an error message:
undefined is not an object (evaluating this.props.navigation.navigate)
The problem is from this line:
const { navigate } = this.props.navigation;
When I remove this line it shows the screen completly just after click in the buttin error happen. but with this line program starts with error!
What is this problem reason and how I can fix it?
The text was updated successfully, but these errors were encountered: