import { Outlet, useNavigate } from "react-router-dom"; import { useEffect, FormEvent } from "react"; type user = { set: React.Dispatch>; value: string | null; }; type articleSearch = user; export default function Layout({ user, articleSearch, }: { user: user; articleSearch: articleSearch; }) { const navigate = useNavigate(); useEffect(() => { const url = `${import.meta.env.VITE_API_TITLE}/api/v1/profile`; fetch(url, { credentials: "include", method: "get", }) .then((response) => { if (response.ok) { return response.json(); } throw new Error("Network response was not ok."); }) .then((response) => { user.set(response.username); console.log(response.username); }); }, [user]); const logout = () => { fetch(`${import.meta.env.VITE_API_TITLE}/api/v1/logout`, { credentials: "include", method: "get", }).then(() => { user.set(null); }); }; const search = (e: FormEvent) => { e.preventDefault(); const target = e.target as typeof e.target & { search: { value: string }; }; articleSearch.set(target.search.value); navigate("/"); }; return ( <>
{/*slide in nav*/} {/*Header*/}
{/*Title*/}

☕ Spring!

Welcome to my Blog

); }