Skip to content

Commit

Permalink
moved user and display name generation into UserProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronGibson2 committed Feb 13, 2024
1 parent d3e4e25 commit 259dacb
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions client/src/contexts/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,9 @@ import { generateName } from '../utils/scripts';
const UserContext = createContext<UserType>({
userID: "something",
displayName: "default",
pfp: "null"
pfp: "picture"
});

const [user, setUser] = useState<UserType>({
userID: "something",
displayName: "default",
pfp: "null"
});

useEffect(() => {
user.displayName = generateName();
}, []);

export const useUser = () => {
return useContext(UserContext);
}
Expand All @@ -28,8 +18,23 @@ export const changeUsername = (newUsername: string) => {
setUser
}
*/
const user = useUser();

export const UserProvider = ({ children }: {children: React.ReactNode}) => {
// const [userID, setUserID] = useState<string>();
// const [displayName, setDisplayName] = useState<string>();
// const [pfp, setPfp] = useState<string>();

const [user, setUser] = useState<UserType>({
userID: "something",
displayName: "default",
pfp: "picture"
})

useEffect(() => {
user.displayName = generateName();
}, []);

return (
<UserContext.Provider value={user}>
{children}
Expand Down

0 comments on commit 259dacb

Please sign in to comment.