Skip to content

Instantly share code, notes, and snippets.

@vaibhavgehani
Created October 10, 2022 06:08
Show Gist options
  • Save vaibhavgehani/0a2fec814682fd7715ce6db57fb881cf to your computer and use it in GitHub Desktop.
Save vaibhavgehani/0a2fec814682fd7715ce6db57fb881cf to your computer and use it in GitHub Desktop.
import * as React from 'react';
import {
NavigationContainerRef,
DrawerActions,
StackActions,
} from '@react-navigation/native';
export const navigationRef = React.createRef<NavigationContainerRef>();
export function navigate(
name,
params,
) {
navigationRef.current?.navigate(name, params);
}
export function replace(
name,
params,
) {
navigationRef.current?.dispatch(StackActions.replace(name, params));
}
export function push(name, params) {
navigationRef.current?.dispatch(StackActions.push(name, params));
}
export function goBack() {
navigationRef.current?.canGoBack() && navigationRef.current?.goBack();
}
export function popToTop() {
navigationRef.current?.dispatch(StackActions.popToTop());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment