Home > Software design >  Unexpected go back on react-navigation
Unexpected go back on react-navigation

Time:07-21

I have a nested stack in my project. Everything works fine but when I click a button that takes you to a page where at first it has to load the user list with useEffect, the page does a navigation.goBack (). If I take useEffect off the page, when I click the button it goes to the right page

CodePudding user response:

This is the error

This is the video that show the error

CodePudding user response:

Without a code snippet its pretty hard to answer, however my intuition tells me you're doing something like this

<Button onPress={navigation.goBack()}> {Back arrow in the top left corner} </Button>

When you should be doing something like this:

<Button onPress={(e)=>navigation.goBack()}> {Back arrow in the top left corner} </Button>

The difference here is the (e) => inside the onPress/onClick (depending on what framework you're using) without the (e) => the function is called immediately when the button is rendered. Again, not 100% sure without the code snippet

  • Related