keyan 18910fa2ed Revert "shield your eyes; massive, squashed refactor; nextjs/react/react-dom/apollo upgrades"
This reverts commit d0314ab73c42ebf85fe2f418dddd681af45dbc55.
2023-07-23 09:16:12 -05:00

27 lines
566 B
JavaScript

import React, { useContext } from 'react'
import { useQuery } from '@apollo/client'
import { ME } from '../fragments/users'
export const MeContext = React.createContext({
me: null
})
export function MeProvider ({ me, children }) {
const { data } = useQuery(ME, { pollInterval: 1000, fetchPolicy: 'cache-and-network' })
const contextValue = {
me: data?.me || me
}
return (
<MeContext.Provider value={contextValue}>
{children}
</MeContext.Provider>
)
}
export function useMe () {
const { me } = useContext(MeContext)
return me
}