import { createContext, FunctionComponent } from 'react'
import { CurrentUserQuery, useCurrentUserQuery } from '../gql'

export const UserContext = createContext<
  CurrentUserQuery['currentUser'] | undefined
>(undefined)

export const UserProvider: FunctionComponent = ({ children }) => {
  const user = useCurrentUserQuery()
  return (
    <UserContext.Provider value={user.data?.currentUser}>
      {children}
    </UserContext.Provider>
  )
}
