import { Fragment, type ReactNode, useState } from "react"; import { BrowserRouter, Link, Navigate, Outlet, Route, Routes, useParams, } from "react-router"; import { errorMessage } from "./api"; import { AuthProvider, useAuth } from "./auth/AuthContext"; import { LoginForm } from "./auth/LoginForm"; import { RequireAuth } from "./auth/RequireAuth"; import { BookDetail } from "./books/BookDetail"; import { BookForm } from "./books/BookForm"; import { BookList } from "./books/BookList"; import { AlertIcon, BookIcon } from "./icons"; import { ThemeToggle } from "./ThemeToggle"; import { errorText, secondaryButton } from "./ui"; export function App() { return ( ); } export function AppRoutes() { return ( } /> }> }> } /> } /> } /> } /> } /> ); } function KeyedByBookId({ children }: { children: ReactNode }) { const { id } = useParams(); return {children}; } function Shell() { const { user, logout } = useAuth(); const [error, setError] = useState(null); return ( My Library {user?.username} logout().catch((err) => setError(errorMessage(err))) } > Log out {error && ( {error} )} ); }
{error}