Skip to content
Snippets Groups Projects
UserContext.tsx 773 B
import React, { createContext, useState } from 'react';
import { IProfile, Role } from '../types/Profile';

interface ContextProps {
  profile: IProfile;
  setProfile: (profile: IProfile) => void;
}

// Context
const initialState: IProfile = {
  externalId: 'abcd',
  studentCardNumber: '1234',
  roomNumber: 104,
  role: Role.User,
  email: 'alma@gmail.com',
  name: 'Nagy Gizike',
  warnings: [],
  notices: [],
};
export const userContext = createContext({} as ContextProps);
const { Provider } = userContext;

export const UserStateProvider: React.FC = ({ children }) => {
  const [profile, setProfile] = useState<IProfile>(initialState);

  return <Provider value={{ profile, setProfile }}>{children}</Provider>;
};

export default { userContext, UserStateProvider };