mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
24 lines
716 B
TypeScript
24 lines
716 B
TypeScript
import React from 'react';
|
|
import { Features } from './types';
|
|
|
|
export interface ApplicationContext {
|
|
features: Features;
|
|
}
|
|
|
|
const ApplicationContextDefaultValue = {} as ApplicationContext
|
|
export const ApplicationContext = React.createContext(
|
|
ApplicationContextDefaultValue
|
|
);
|
|
|
|
export function withAuthenticatedContexApplicationContext<T extends ApplicationContext>(Component: React.ComponentType<T>) {
|
|
return class extends React.Component<Omit<T, keyof ApplicationContext>> {
|
|
render() {
|
|
return (
|
|
<ApplicationContext.Consumer>
|
|
{authenticatedContext => <Component {...this.props as T} features={authenticatedContext} />}
|
|
</ApplicationContext.Consumer>
|
|
);
|
|
}
|
|
};
|
|
}
|