Skip to content

Commit

Permalink
fix: improve usePageContext() JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed May 28, 2024
1 parent 9e74b57 commit 0f83834
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/vike-react/src/hooks/usePageContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ function PageContextProvider({ pageContext, children }: { pageContext: PageConte
return <reactContext.Provider value={pageContext}>{children}</reactContext.Provider>
}

/** Access the pageContext from any React component */
function usePageContext() {
/**
* Access `pageContext` from any React component.
*
* https://vike.dev/usePageContext
*/
function usePageContext(): PageContext {
const { reactContext } = globalObject
const pageContext = useContext(reactContext)
/* React throws an error upon wrong hook usage, so I guess a nice error message isn't needed? And I guess we can therefore assume and assert pageContext to have been provided? Let's see if users report back an assert() failure.
Expand Down

0 comments on commit 0f83834

Please sign in to comment.