Dismiss share modals when clicking links
This commit is contained in:
parent
3875c1ab1e
commit
18b33389b5
@ -11,6 +11,7 @@ import { PiXLogo } from 'react-icons/pi';
|
||||
import { SHOW_SOCIAL } from '@/site/config';
|
||||
import { generateXPostText } from '@/utility/social';
|
||||
import { useAppState } from '@/state/AppState';
|
||||
import useOnPathChange from '@/utility/useOnPathChange';
|
||||
|
||||
export default function ShareModal({
|
||||
title,
|
||||
@ -44,6 +45,8 @@ export default function ShareModal({
|
||||
{icon}
|
||||
</div>;
|
||||
|
||||
useOnPathChange(() => setShareModalProps?.(undefined));
|
||||
|
||||
return (
|
||||
<Modal onClose={() => setShareModalProps?.(undefined)}>
|
||||
<div className="space-y-3 md:space-y-4 w-full">
|
||||
|
||||
14
src/utility/useOnPathChange.ts
Normal file
14
src/utility/useOnPathChange.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
export default function useOnPathChange(onPathChange: () => void) {
|
||||
const path = usePathname();
|
||||
|
||||
const initialPath = useRef(path);
|
||||
|
||||
useEffect(() => {
|
||||
if (initialPath.current !== path) {
|
||||
onPathChange();
|
||||
}
|
||||
}, [path, onPathChange]);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user