Skip to content

Commit

Permalink
fix: return undefined instead of throw error upon missing pageContext (
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Sep 6, 2024
1 parent 1c0b011 commit 103f30b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions packages/vike-vue/src/hooks/useData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ const key = 'vike-vue:useData'

/** https://vike.dev/useData */
function useData<Data>(): ShallowReactive<Data> {
const data = inject<ShallowReactive<Data>>(key)
if (!data) throw new Error('setData() not called')
const data = inject<ShallowReactive<Data>>(key)!
return data
}

Expand Down
3 changes: 1 addition & 2 deletions packages/vike-vue/src/hooks/usePageContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const key = 'vike-vue:usePageContext'

/** https://vike.dev/usePageContext */
function usePageContext(): ShallowReactive<PageContext> {
const pageContext = inject<ShallowReactive<PageContext>>(key)
if (!pageContext) throw new Error('setPageContext() not called')
const pageContext = inject<ShallowReactive<PageContext>>(key)!
return pageContext
}

Expand Down

0 comments on commit 103f30b

Please sign in to comment.