discord-clone/hooks/use-origin.ts

17 lines
364 B
TypeScript
Raw Normal View History

2023-11-13 00:29:05 -08:00
import { useEffect, useState } from "react"
2023-10-14 00:06:14 -07:00
export const useOrigin = () => {
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
const origin = typeof window !== "undefined" && window.location.origin ? window.location.origin : "";
2023-11-13 00:29:05 -08:00
2023-10-14 00:06:14 -07:00
if (!mounted) {
return "";
}
return origin;
}