Remove .env

This commit is contained in:
mbaharip
2023-04-21 21:07:19 +07:00
commit b6fc85151a
72 changed files with 9502 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
import { toast } from "react-toastify";
export default function useCopyText() {
return (text: string) => {
if (!navigator.clipboard) {
toast.error("Your browser does not support copying to clipboard.");
return;
}
if (!text) {
toast.error("No text to copy.");
return;
}
navigator.clipboard
.writeText(text)
.then(() => {
toast.success("Copied to clipboard.");
})
.catch(() => {
toast.error("Could not copy to clipboard.");
});
};
}
+58
View File
@@ -0,0 +1,58 @@
import { useState, useEffect } from "react";
type SetValue<T> = (value: T | ((val: T) => T)) => void;
export default function useLocalStorage<T>(key: string, initialValue: T) {
// First check if there is a value in localStorage
function readLocalStorage() {
if (typeof window === "undefined") return initialValue;
try {
const item = window.localStorage.getItem(key);
return item ? JSON.parse(item) : initialValue;
} catch (error) {
console.warn(`Error reading localStorage key “${key}”:`, error);
return initialValue;
}
}
const [storedValue, setStoredValue] = useState<T>(readLocalStorage);
// Create dispatch function to set or remove localStorage
const setValue: SetValue<T> = (value) => {
try {
const valueToStore =
value instanceof Function ? value(storedValue) : value;
setStoredValue(valueToStore);
window.localStorage.setItem(key, JSON.stringify(valueToStore));
} catch (error) {
console.error("Error setting localStorage:", error);
}
};
useEffect(() => {
const handleStorageChange = (event: StorageEvent) => {
if (event.key === key) {
try {
if (event.newValue === null) {
setStoredValue(initialValue);
return;
}
const newValue = JSON.parse(event.newValue);
setStoredValue(newValue);
} catch (error) {
console.log(error);
}
}
};
window.addEventListener("storage", handleStorageChange);
return () => {
window.removeEventListener("storage", handleStorageChange);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [key]);
return [storedValue, setValue] as const;
}