sendou.ink/hooks/common.ts
2021-01-30 13:04:10 +02:00

34 lines
828 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// https://usehooks.com/useDebounce/
import { useColorMode } from "@chakra-ui/react";
import { User as PrismaUser } from "@prisma/client";
import { useSession } from "next-auth/client";
import { useEffect, useState } from "react";
import { theme } from "theme";
export function useDebounce(value: string, delay: number = 500) {
const [debouncedValue, setDebouncedValue] = useState(value);
useEffect(() => {
const handler = setTimeout(() => {
setDebouncedValue(value);
}, delay);
return () => {
clearTimeout(handler);
};
}, [value, delay]);
return debouncedValue;
}
export const useMyTheme = () => {
const { colorMode } = useColorMode();
return theme[colorMode];
};
export const useUser = (): [PrismaUser | undefined | null, boolean] => {
// @ts-ignore
return useSession();
};