react-code-dataset / wp-calypso /client /landing /subscriptions /components /subscription-manager-context /index.tsx
react-code-dataset / wp-calypso /client /landing /subscriptions /components /subscription-manager-context /index.tsx
Download wp-calypso/client/landing/subscriptions/components/subscription-manager-context/index.tsx from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/landing/subscriptions/components/subscription-manager-context/index.tsx
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/landing/subscriptions/components/subscription-manager-context/index.tsx
-
curl -L -o index.tsx https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/landing/subscriptions/components/subscription-manager-context/index.tsx
1.09 kB
| import { createContext, useContext } from 'react'; | |
| export enum SubscriptionsPortal { | |
| Subscriptions = 'subscriptions', | |
| Reader = 'reader', | |
| } | |
| export interface SubscriptionManagerContext { | |
| portal: SubscriptionsPortal; | |
| isSubscriptionsPortal?: boolean; | |
| isReaderPortal?: boolean; | |
| } | |
| const SubscriptionManagerContext = createContext< SubscriptionManagerContext | undefined >( | |
| undefined | |
| ); | |
| export const SubscriptionManagerContextProvider: React.FC< { | |
| portal: SubscriptionsPortal; | |
| children?: React.ReactNode; | |
| } > = ( { portal, ...props } ) => { | |
| return ( | |
| <SubscriptionManagerContext.Provider | |
| value={ { | |
| portal, | |
| isSubscriptionsPortal: portal === SubscriptionsPortal.Subscriptions, | |
| isReaderPortal: portal === SubscriptionsPortal.Reader, | |
| } } | |
| { ...props } | |
| /> | |
| ); | |
| }; | |
| export const useSubscriptionManagerContext = (): SubscriptionManagerContext => { | |
| const context = useContext( SubscriptionManagerContext ); | |
| if ( ! context ) { | |
| throw new Error( | |
| 'useSubscriptionManagerContext must be used within a SubscriptionManagerContextProvider' | |
| ); | |
| } | |
| return context; | |
| }; | |