From d916fba0a54ca2ee89f1de1a4dcc0ee71a3a24c5 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Tue, 24 May 2022 19:00:40 +0200
Subject: chore: close search form when launching search

---
 src/utils/hooks/use-route-change.tsx | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 src/utils/hooks/use-route-change.tsx

(limited to 'src/utils/hooks/use-route-change.tsx')

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;
-- 
cgit v1.2.3

