File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -2,5 +2,6 @@ export * from './MobileContext';
22export * from './MobileProvider' ;
33export * from './useMobile' ;
44export * from './usePlatform' ;
5+ export * from './withPlatform' ;
56export * from './withMobile' ;
67export * from './constants' ;
Original file line number Diff line number Diff line change 1+ import * as React from 'react' ;
2+
3+ import { getComponentName } from '../utils/getComponentName' ;
4+
5+ import { MobileContext } from './MobileContext' ;
6+ import type { MobileContextProps } from './MobileContext' ;
7+
8+ export type WithPlatformProps = { platform : MobileContextProps [ 'platform' ] } ;
9+
10+ export function withPlatform < T extends WithPlatformProps > (
11+ WrappedComponent : React . ComponentType < T > ,
12+ ) : React . ComponentType < Omit < T , keyof WithPlatformProps > > {
13+ const componentName = getComponentName ( WrappedComponent ) ;
14+
15+ return class WithPlatformComponent extends React . Component < Omit < T , keyof WithPlatformProps > > {
16+ static displayName = `withPlatform(${ componentName } )` ;
17+ static contextType = MobileContext ;
18+ declare context : React . ContextType < typeof MobileContext > ;
19+
20+ render ( ) {
21+ return < WrappedComponent { ...( this . props as T ) } platform = { this . context . platform } /> ;
22+ }
23+ } ;
24+ }
You can’t perform that action at this time.
0 commit comments