MCPcopy Create free account
hub / github.com/dailydotdev/apps / GoBackButton

Function GoBackButton

packages/shared/src/components/post/GoBackHeaderMobile.tsx:33–81  ·  view source on GitHub ↗
({
  className,
  showLogo = true,
  fallbackPath,
}: WithClassNameProps & {
  showLogo?: boolean;
  fallbackPath?: string;
})

Source from the content-addressed store, hash-verified

31};
32
33export const GoBackButton = ({
34 className,
35 showLogo = true,
36 fallbackPath,
37}: WithClassNameProps & {
38 showLogo?: boolean;
39 fallbackPath?: string;
40}): JSX.Element | null => {
41 const router = useRouter();
42 const goHome = useCallback(() => router.push('/'), [router]);
43 const featureTheme = useFeatureTheme();
44
45 const canGoBack =
46 globalThis?.history?.length > 1 && (checkSameSite() || isDevelopment);
47
48 const goBack = useCallback(() => {
49 if (canGoBack) {
50 router.back();
51 return;
52 }
53
54 if (fallbackPath) {
55 router.push(fallbackPath);
56 }
57 }, [canGoBack, fallbackPath, router]);
58
59 const logoButton = showLogo ? (
60 <Logo
61 className="my-2"
62 onLogoClick={goHome}
63 position={LogoPosition.Initial}
64 featureTheme={featureTheme}
65 />
66 ) : null;
67
68 return canGoBack || fallbackPath ? (
69 <Button
70 icon={<ArrowIcon className="-rotate-90" />}
71 size={ButtonSize.Small}
72 variant={ButtonVariant.Tertiary}
73 onClick={goBack}
74 className={className}
75 type="button"
76 aria-label="Go back"
77 />
78 ) : (
79 logoButton
80 );
81};
82
83export function GoBackHeaderMobile({
84 children,

Callers

nothing calls this directly

Calls 5

useFeatureThemeFunction · 0.90
checkSameSiteFunction · 0.85
pushMethod · 0.80
backMethod · 0.80
useRouterFunction · 0.50

Tested by

no test coverage detected