I want to go back to the previous page when Apollo Client error.graphQLErrors has an error with a specific message from the backend server.
Below is the snippet of my code,
const Detail = () => {
const { snackbar } = useSnackbar();
const history = useHistory();
return (
<Compo query={graphQLQuery}>
{({ data, error, }) => {
if (error?.graphQLErrors[0]?.extensions?.debugMessage.includes('Specific Error')) {
history.goBack();
snackbar('Specific Error');
return <></>;
} else {
//render another component
}
}}
</Compo>
);
Issue is since the render is called twice, when the error happens, history.goBack() is executed twice and I'm taken two pages back.
I'm able to avoid this by removing <React.StrictMode> encapsulating <App> component.
Is there a better way to do this?
I'm trying to avoid removing <React.StrictMode> since it's been there since a long time.