diff --git a/src/create-context.ts b/src/create-context.ts index ed0169f..5a624a1 100644 --- a/src/create-context.ts +++ b/src/create-context.ts @@ -20,8 +20,9 @@ interface ContextDetail { Context: Context; callback: (value: T) => void; + // These properties will not exist if a context consumer lacks a provider value: T; - unsubscribe: (this: Context) => void; + unsubscribe?: (this: Context) => void; } function makeContext(component: ComponentCreator): Creator { diff --git a/src/use-context.ts b/src/use-context.ts index df3bc88..53be227 100644 --- a/src/use-context.ts +++ b/src/use-context.ts @@ -55,7 +55,7 @@ const useContext = hook(class extends Hook<[Context], T, Element> { composed: true, // to pass ShadowDOM boundaries })); - const { unsubscribe, value } = detail as ContextDetail; + const { unsubscribe = null, value } = detail as ContextDetail; this.value = unsubscribe ? value : Context.defaultValue;