From 103f30b57c97aba2e25a43c7db1b3547c5624a3e Mon Sep 17 00:00:00 2001 From: Romuald Brillout Date: Fri, 6 Sep 2024 10:02:14 +0200 Subject: [PATCH] fix: return undefined instead of throw error upon missing pageContext (fix vikejs/vike-react#147) --- packages/vike-vue/src/hooks/useData.ts | 3 +-- packages/vike-vue/src/hooks/usePageContext.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/vike-vue/src/hooks/useData.ts b/packages/vike-vue/src/hooks/useData.ts index 0c385f7e..80806260 100644 --- a/packages/vike-vue/src/hooks/useData.ts +++ b/packages/vike-vue/src/hooks/useData.ts @@ -9,8 +9,7 @@ const key = 'vike-vue:useData' /** https://vike.dev/useData */ function useData(): ShallowReactive { - const data = inject>(key) - if (!data) throw new Error('setData() not called') + const data = inject>(key)! return data } diff --git a/packages/vike-vue/src/hooks/usePageContext.ts b/packages/vike-vue/src/hooks/usePageContext.ts index 8b8348b7..70ea732a 100644 --- a/packages/vike-vue/src/hooks/usePageContext.ts +++ b/packages/vike-vue/src/hooks/usePageContext.ts @@ -10,8 +10,7 @@ const key = 'vike-vue:usePageContext' /** https://vike.dev/usePageContext */ function usePageContext(): ShallowReactive { - const pageContext = inject>(key) - if (!pageContext) throw new Error('setPageContext() not called') + const pageContext = inject>(key)! return pageContext }