summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-05-24 19:00:40 +0200
committerArmand Philippot <git@armandphilippot.com>2022-05-24 19:00:40 +0200
commitd916fba0a54ca2ee89f1de1a4dcc0ee71a3a24c5 (patch)
tree4ee4c73f4e9bbe06e7fbe375b10be7e5cc9cdb6c /src/utils
parent06b46debea14c198ee5de7f7342122a12062eb57 (diff)
chore: close search form when launching search
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/hooks/use-route-change.tsx12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/utils/hooks/use-route-change.tsx b/src/utils/hooks/use-route-change.tsx
new file mode 100644
index 0000000..82e01a1
--- /dev/null
+++ b/src/utils/hooks/use-route-change.tsx
@@ -0,0 +1,12 @@
+import { useRouter } from 'next/router';
+import { useEffect } from 'react';
+
+const useRouteChange = (callback: () => void) => {
+ const { events } = useRouter();
+
+ useEffect(() => {
+ events.on('routeChangeStart', callback);
+ }, [events, callback]);
+};
+
+export default useRouteChange;