Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import { ArrowLeftIcon } from "@heroicons/react/24/outline";
2import { memo, useCallback } from "react";
3import { useNavigate, useNavigationType } from "react-router";
4
5interface BackButtonProps {
6 path?: string;
7}
8
9const BackButton = ({ path }: BackButtonProps) => {
10 const navigate = useNavigate();
11 const navType = useNavigationType();
12
13 const handleBack = useCallback(() => {
14 if (path) {
15 navigate(path);
16 } else if (navType === "POP") {
17 navigate("/");
18 } else {
19 navigate(-1);
20 }
21 }, [navType, navigate, path]);
22
23 return (
24 <button
25 className="rounded-lg px-2 py-1 hover:bg-gray-100 dark:hover:bg-gray-800"
26 onClick={handleBack}
27 type="button"
28 >
29 <ArrowLeftIcon className="size-5" />
30 </button>
31 );
32};
33
34export default memo(BackButton);