Skip to content

Commit

Permalink
optimize useContext call (#2226)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdynnl authored Jul 18, 2024
1 parent 1afe035 commit 2ae7d1d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/solid/src/reactive/signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,9 @@ export function createContext<T>(
* @description https://docs.solidjs.com/reference/component-apis/use-context
*/
export function useContext<T>(context: Context<T>): T {
return Owner && Owner.context && Owner.context[context.id] !== undefined
? Owner.context[context.id]
let value: undefined | T;
return Owner && Owner.context && (value = Owner.context[context.id]) !== undefined
? value
: context.defaultValue;
}

Expand Down

0 comments on commit 2ae7d1d

Please sign in to comment.