diff --git a/app/components/Layout/UserItem.tsx b/app/components/Layout/UserItem.tsx index 6d95362ae..c1db90a99 100644 --- a/app/components/Layout/UserItem.tsx +++ b/app/components/Layout/UserItem.tsx @@ -1,9 +1,9 @@ -import { useUserContext } from "~/root"; +import { useUser } from "~/utils"; import { DiscordIcon } from "../icons/Discord"; // TODO: redirect to same page on login export function UserItem() { - const user = useUserContext(); + const user = useUser(); if (user) return ( diff --git a/app/root.tsx b/app/root.tsx index 0a2501901..da02c4cb9 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -33,20 +33,12 @@ export const loader: LoaderFunction = ({ context }) => { export let unstable_shouldReload = () => false; -const UserContext = React.createContext(null); - -export const useUserContext = () => React.useContext(UserContext); - export default function App() { - const data = useLoaderData(); - return ( - - - - - + + + ); } diff --git a/app/utils/index.ts b/app/utils/index.ts index d499fb3e1..2d22ac4a4 100644 --- a/app/utils/index.ts +++ b/app/utils/index.ts @@ -1,4 +1,4 @@ -import { json } from "remix"; +import { json, useMatches } from "remix"; export const makeTitle = (endOfTitle: string) => `sendou.ink | ${endOfTitle}`; @@ -18,6 +18,12 @@ export type LoggedInUser = { discordAvatar: string; } | null; +export const useUser = () => { + const [root] = useMatches(); + + return root.data as LoggedInUser; +}; + export type Serialized = { [P in keyof T]: T[P] extends Date ? string : Serialized; };