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, useRef } from 'react'; | |
| const useInactivityTimeout = (timeoutInHours) => { | |
| const timeoutInMillis = timeoutInHours * 60 * 60 * 1000; | |
| const timer = useRef(null); | |
| useEffect(() => { | |
| if (navigator.userActivation) { | |
| if(navigator.userActivation.isActive){ | |
| if (timer.current) { |
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 { useState } from "react"; | |
| export const useClipboard = () => { | |
| const [isCopied, setIsCopied] = useState(false); | |
| const copyToClipboard = (text: string) => { | |
| navigator.clipboard.writeText(text).then( | |
| () => setIsCopied(true), | |
| () => setIsCopied(false) | |
| ); |
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 const useFetch = <T>(url: string) => { | |
| const [data, setData] = useState<T | any>(); | |
| const [loading, setLoading] = useState(true); | |
| const [error, setError] = useState<Error | null>(null); | |
| useEffect(() => { | |
| const fetchData = async () => { | |
| try { |
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 { useState } from "react"; | |
| export const useToggle = (initialValue: boolean = false) => { | |
| const [value, setValue] = useState<boolean>(initialValue); | |
| const toggle = () => { | |
| setValue((prevValue) => !prevValue); | |
| }; | |
| return [value, toggle] as const; |
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, useRef } from "react"; | |
| export const usePrevious = <T>(value: T) => { | |
| const ref = useRef<T>(); | |
| useEffect(() => { | |
| ref.current = value; | |
| }, [value]); | |
| return ref.current; | |
| }; | |
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 const useOnlineStatus = () => { | |
| const [isOnline, setIsOnline] = useState(navigator.onLine); | |
| const handleOnline = () => setIsOnline(true); | |
| const handleOffline = () => setIsOnline(false); | |
| useEffect(() => { | |
| window.addEventListener("online", handleOnline); |