Fork of the excellent esp8266-react - https://github.com/rjwats/esp8266-react
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
725 B
27 lines
725 B
import React from 'react';
|
|
import { Features } from './types';
|
|
|
|
export interface FeaturesContext {
|
|
features: Features;
|
|
}
|
|
|
|
const FeaturesContextDefaultValue = {} as FeaturesContext
|
|
export const FeaturesContext = React.createContext(
|
|
FeaturesContextDefaultValue
|
|
);
|
|
|
|
export interface WithFeaturesProps {
|
|
features: Features;
|
|
}
|
|
|
|
export function withFeatures<T extends WithFeaturesProps>(Component: React.ComponentType<T>) {
|
|
return class extends React.Component<Omit<T, keyof WithFeaturesProps>> {
|
|
render() {
|
|
return (
|
|
<FeaturesContext.Consumer>
|
|
{featuresContext => <Component {...this.props as T} features={featuresContext.features} />}
|
|
</FeaturesContext.Consumer>
|
|
);
|
|
}
|
|
};
|
|
}
|