This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hi my name is Shery. I am a fullstack software dev. | |
Checkout my repos. | |
Hit me up at [email protected] for my resume. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useEffect, useState, useTransition } from "react"; | |
import { usePathname, useSearchParams } from "next/navigation"; | |
import { useRouter } from "next/navigation"; | |
export function debounced<T extends (...args: any[]) => any>( | |
func: T, | |
duration: number, | |
): (...args: Parameters<T>) => ReturnType<T> { | |
let timeoutId: NodeJS.Timeout; | |
let result: ReturnType<T>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type FunctionType = (...args: any[]) => any; | |
function debounced<T extends FunctionType>( | |
func: T, | |
duration: number | |
): (...args: Parameters<T>) => ReturnType<T> { | |
let timeoutId: NodeJS.Timeout; | |
let result: ReturnType<T>; | |
return (...args: Parameters<T>) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from "react"; | |
export function useLocalStorage<T>(key: string, initialValue: T) { | |
const [state, setState] = useState<T>(() => { | |
const json = localStorage.getItem(key); | |
return json ? JSON.parse(json) : initialValue; | |
}); | |
// a wrapper over setState, but it also save given value to localStorage | |
function setStorage(value: T | ((v: T) => T)) { |