1

I'm having my screens in a stack navigation and I need to perform an AJAX fetch every time I go to the dashboard screen. I tried using the didComponentMount of the dashboard, but since dashboard is on the top of the stack, it never actually unmounts and mounts. How can I detect, that the user has transitioned to the dahsboard screen? If there was a way where a navigation would sent action to the store every time it navigated somewhere, that would be nice as well....

What should I do?

Edit: I'm using react & redux. And I'm tinkering with this: https://github.com/react-navigation/react-navigation/blob/master/docs/guides/Screen-Tracking.md but I feel there must a better way than modifying the specific navigation. I think there must be a way to just add a middleware or just some code in the given navigation component I want to observe...

Novellizator
  • 13,633
  • 9
  • 43
  • 65
  • Please post some code for review with what you've tried. Are you using redux or just local state. Have you tried passing a "refresh" function that can be called in the child when the user is navigating back? – SteveB Jan 28 '18 at 16:04
  • A refresh function? Could you clarify please? – Novellizator Jan 28 '18 at 16:29
  • Check out this stackoveflow for an example: https://stackoverflow.com/questions/44223727/react-navigation-goback-and-update-parent-state and/or this one: https://stackoverflow.com/questions/45489343/react-navigation-back-and-goback-not-working – SteveB Jan 28 '18 at 16:30
  • If the links I provided didn't help, please post your code and I'll try to help you with the functions. I went through a similar issue when writing some of my own code a few months back. – SteveB Jan 29 '18 at 14:27
  • @SteveB hey, the issue is that the dashboard points to many components and I didn't feel like adding trigger to every component I can to back from dashbord. In the end I did it as follows: I used "onNavigationStateChange" which dispatch an action whenever a screen changes and then I hooked up a saga to respond to the NAVIGATION_CHANGED action when it changed to the dashboard screen – Novellizator Jan 30 '18 at 17:39
  • 1
    Sounds like you found a good solution.. Good job – SteveB Jan 30 '18 at 17:40

0 Answers0