Skip to content

Instantly share code, notes, and snippets.

View SheryConcepts's full-sized avatar
🐢
working

Sheharyar SheryConcepts

🐢
working
View GitHub Profile
@SheryConcepts
SheryConcepts / AboutMe
Last active January 8, 2024 11:53
About Me
Hi my name is Shery. I am a fullstack software dev.
Checkout my repos.
Hit me up at chsheharyarahmed@gmail.com for my resume.
@SheryConcepts
SheryConcepts / searchParamsUtilities.ts
Created October 1, 2023 16:04
Utilities for handling search params in Nextjs applications.
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>;
@SheryConcepts
SheryConcepts / debounced.ts
Last active July 8, 2023 18:58
Typescript Debouncing Utility Function.
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>) => {
@SheryConcepts
SheryConcepts / useLocalStorage.ts
Last active June 9, 2023 08:00
React hook for localStorage. Has the same interface as useState.
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)) {