Skip to content

Commit 9f6e6b3

Browse files
committed
dev: add warning when context is null
1 parent 41fa6c1 commit 9f6e6b3

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

packages/solid/src/reactive/signal.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,9 +1201,11 @@ export function createContext<T>(
12011201
*/
12021202
export function useContext<T>(context: Context<T>): T {
12031203
let value: undefined | T;
1204-
return Owner && Owner.context && (value = Owner.context[context.id]) !== undefined
1205-
? value
1206-
: context.defaultValue;
1204+
let ctx = Owner && Owner.context && (value = Owner.context[context.id]) !== undefined
1205+
? value
1206+
: context.defaultValue;
1207+
IS_DEV && !ctx && console.warn("`useContext` returns null. Is it being called inside a provider?")
1208+
return ctx;
12071209
}
12081210

12091211
export type ResolvedJSXElement = Exclude<JSX.Element, JSX.ArrayElement>;

0 commit comments

Comments
 (0)