From 7327a69b55a20b99b14ee0803d6cf5f8b88c45ef Mon Sep 17 00:00:00 2001 From: Factiven Date: Wed, 13 Sep 2023 00:45:53 +0700 Subject: Update v4 - Merge pre-push to main (#71) * Create build-test.yml * initial v4 commit * update: github workflow * update: push on branch * Update .github/ISSUE_TEMPLATE/bug_report.md * configuring next.config.js file --- lib/hooks/isOpenState.js | 17 +++++++++++++++++ lib/hooks/useDebounce.js | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 lib/hooks/isOpenState.js create mode 100644 lib/hooks/useDebounce.js (limited to 'lib/hooks') 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 ( + + {children} + + ); +}; + +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; +} -- cgit v1.2.3