new-personal-site/components/lib/hooks/useLocalUser.tsx
Benjamin Toby 5587024789 Updates
2025-01-05 07:25:38 +01:00

26 lines
733 B
TypeScript

import { LocalStorageDict } from "@/dict/local-storage-dict";
import { DATASQUIREL_LoggedInUser } from "@moduletrace/datasquirel/package-shared/types";
import React from "react";
export default function useLocalUser() {
const [user, setUser] = React.useState<
DATASQUIREL_LoggedInUser | null | undefined
>(undefined);
React.useEffect(() => {
try {
const localUserJSON = localStorage.getItem(
LocalStorageDict["User"]
);
if (localUserJSON) {
const localUser = JSON.parse(localUserJSON);
setUser(localUser);
}
} catch (error) {
setUser(null);
}
}, []);
return { user };
}