Skip to content
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

How to get the screen name on which the error occurs #153

Open
faizanbuggy opened this issue Oct 1, 2021 · 5 comments
Open

How to get the screen name on which the error occurs #153

faizanbuggy opened this issue Oct 1, 2021 · 5 comments

Comments

@faizanbuggy
Copy link

HI,
How can we get the screen name on which the error occurs?
It is only returning the error message.

@prpgan
Copy link

prpgan commented Dec 6, 2021

Did you find anything on this issue?, i am looking for the same.

@faizanbuggy
Copy link
Author

Not by this library. But got a workflow for this by using react-navigation. So, whenever the error occurs I am getting the screen from the react-navigation. This screen would be prior to the error screen. Hope this would help you!

@ssokhavirith
Copy link

ssokhavirith commented Jan 10, 2022

In case you use react navigation (v6 but might work also in v5) you can use global variable.
First you need to find a way to get the current active screen and when the active screen changes set the global variable to the current screen

//function

const onStateChange = async () => {
    const previousRouteName = routeNameRef.current;
    const currentRouteName = navigationRef?.getCurrentRoute && navigationRef?.getCurrentRoute()?.name;

    if (currentRouteName) {
       (global as any).currentRouteName = currentRouteName; //------set the current route name to global variable
      routeNameRef.current = currentRouteName;
    }
  };
  const onReady = () => {
    const name = (navigationRef?.getCurrentRoute && navigationRef?.getCurrentRoute()?.name) || '';
    if (name) {
      (global as any).currentRouteName = name;
      routeNameRef.current = name;
    }
  };

//in your navigation container

 <NavigationContainer
      ref={navigationRef}
      onReady={onReady}
      onStateChange={onStateChange}
      theme={isDark ? DarkTheme : DefaultTheme}
    >...</NavigationContainer>

Then you can access your current route name from global variable
(global as any).currentRouteName

@faizanbutt
Copy link

@ssokhavirith but this return the second last screen not the current screen on which error has occured. For instance; I have a stack screen inside a bottom navigation and error occurs on the stack screen. So the currentscreen always points to the bottom tab in which the stack screen (error occured screen) lies.

@mednche
Copy link

mednche commented Feb 18, 2023

I would also like to know how to get the name of the screen on which the error occured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants