Shaves off an easy 1.4kb win from the global package (#8382)

pull/8363/head
Alex van Andel 2023-04-19 21:23:49 +02:00 committed by GitHub
parent 33a69d3ef6
commit d3f1f8b906
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import * as React from "react"; import { createContext, useContext, createElement } from "react";
import type { AppFlags } from "../config"; import type { AppFlags } from "../config";
@ -12,7 +12,7 @@ export type Flags = AppFlags;
/** /**
* Allows you to access the flags from context * Allows you to access the flags from context
*/ */
const FeatureContext = React.createContext<Flags | null>(null); const FeatureContext = createContext<Flags | null>(null);
/** /**
* Accesses the evaluated flags from context. * Accesses the evaluated flags from context.
@ -21,7 +21,7 @@ const FeatureContext = React.createContext<Flags | null>(null);
* this component. * this component.
*/ */
export function useFlagMap() { export function useFlagMap() {
const flagMapContext = React.useContext(FeatureContext); const flagMapContext = useContext(FeatureContext);
if (flagMapContext === null) throw new Error("Error: useFlagMap was used outside of FeatureProvider."); if (flagMapContext === null) throw new Error("Error: useFlagMap was used outside of FeatureProvider.");
return flagMapContext as Flags; return flagMapContext as Flags;
} }
@ -52,5 +52,5 @@ export function useFlagMap() {
* so you might not need this at all._ * so you might not need this at all._
*/ */
export function FeatureProvider<F extends Flags>(props: { value: F; children: React.ReactNode }) { export function FeatureProvider<F extends Flags>(props: { value: F; children: React.ReactNode }) {
return React.createElement(FeatureContext.Provider, { value: props.value }, props.children); return createElement(FeatureContext.Provider, { value: props.value }, props.children);
} }