mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-12 06:11:35 -05:00
5462fcd128
* Update `User` type * Set `layout-react`: `subscriptions/successful-subscription-react` * Set `layout-react`: `subscriptions/canceled-subscription-react` * Set `layout-react`: `subscriptions/dashboard-react` * Set `layout-react`: `subscriptions/team/invite-managed`, `subscriptions/team/invite`, `subscriptions/team/invite_logged_out` * Set `layout-react`: `subscriptions/team/group-invites` * Add `header-footer-react` to subscription/base.js * Fix: Replace `date-type` by `data-type` * Fix SubscriptionControllerTests GitOrigin-RevId: b9049a9093a700b3be1bf33809e3a1494022350a
25 lines
683 B
TypeScript
25 lines
683 B
TypeScript
import { createContext, FC, useContext, useMemo } from 'react'
|
|
import getMeta from '../../utils/meta'
|
|
import { LoggedOutUser, User } from '../../../../types/user'
|
|
|
|
export const UserContext = createContext<User | LoggedOutUser | undefined>(
|
|
undefined
|
|
)
|
|
|
|
export const UserProvider: FC = ({ children }) => {
|
|
const user = useMemo(() => getMeta('ol-user'), [])
|
|
|
|
return <UserContext.Provider value={user}>{children}</UserContext.Provider>
|
|
}
|
|
|
|
export function useUserContext() {
|
|
const context = useContext(UserContext)
|
|
|
|
if (!context) {
|
|
throw new Error(
|
|
'useUserContext is only available inside UserContext, or `ol-user` meta is not defined'
|
|
)
|
|
}
|
|
|
|
return context
|
|
}
|