aboutsummaryrefslogtreecommitdiff
path: root/lib/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'lib/hooks')
-rw-r--r--lib/hooks/isOpenState.js17
-rw-r--r--lib/hooks/useDebounce.js17
2 files changed, 34 insertions, 0 deletions
diff --git a/lib/hooks/isOpenState.js b/lib/hooks/isOpenState.js
new file mode 100644
index 0000000..6aade61
--- /dev/null
+++ b/lib/hooks/isOpenState.js
@@ -0,0 +1,17 @@
+import React, { createContext, useContext, useState } from "react";
+
+const SearchContext = createContext();
+
+export const SearchProvider = ({ children }) => {
+ const [isOpen, setIsOpen] = useState(false);
+
+ return (
+ <SearchContext.Provider value={{ isOpen, setIsOpen }}>
+ {children}
+ </SearchContext.Provider>
+ );
+};
+
+export function useSearch() {
+ return useContext(SearchContext);
+}
diff --git a/lib/hooks/useDebounce.js b/lib/hooks/useDebounce.js
new file mode 100644
index 0000000..e3a1631
--- /dev/null
+++ b/lib/hooks/useDebounce.js
@@ -0,0 +1,17 @@
+import { useEffect, useState } from "react";
+
+export default function useDebounce(value, delay) {
+ const [debounceValue, setDebounceValue] = useState(value);
+
+ useEffect(() => {
+ const timeoutId = setTimeout(() => {
+ setDebounceValue(value);
+ }, delay);
+
+ return () => {
+ clearTimeout(timeoutId);
+ };
+ }, [value, delay]);
+
+ return debounceValue;
+}