Skip to content

Commit 103f30b

Browse files
committed
fix: return undefined instead of throw error upon missing pageContext (fix vikejs/vike-react#147)
1 parent 1c0b011 commit 103f30b

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

packages/vike-vue/src/hooks/useData.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ const key = 'vike-vue:useData'
99

1010
/** https://vike.dev/useData */
1111
function useData<Data>(): ShallowReactive<Data> {
12-
const data = inject<ShallowReactive<Data>>(key)
13-
if (!data) throw new Error('setData() not called')
12+
const data = inject<ShallowReactive<Data>>(key)!
1413
return data
1514
}
1615

packages/vike-vue/src/hooks/usePageContext.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ const key = 'vike-vue:usePageContext'
1010

1111
/** https://vike.dev/usePageContext */
1212
function usePageContext(): ShallowReactive<PageContext> {
13-
const pageContext = inject<ShallowReactive<PageContext>>(key)
14-
if (!pageContext) throw new Error('setPageContext() not called')
13+
const pageContext = inject<ShallowReactive<PageContext>>(key)!
1514
return pageContext
1615
}
1716

0 commit comments

Comments
 (0)