Skip to content

Commit

Permalink
fix: remove counterproductive assert() (fix #115)
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed May 28, 2024
1 parent 0f83834 commit 2cc16cf
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 12 deletions.
6 changes: 0 additions & 6 deletions packages/vike-react/src/hooks/usePageContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ export { PageContextProvider }
import React, { useContext } from 'react'
import { getGlobalObject } from '../utils/getGlobalObject.js'
import type { PageContext } from 'vike/types'
import { assert } from '../utils/assert.js'

const globalObject = getGlobalObject('PageContextProvider.ts', {
reactContext: React.createContext<PageContext>(undefined as never)
})

function PageContextProvider({ pageContext, children }: { pageContext: PageContext; children: React.ReactNode }) {
assert(pageContext)
const { reactContext } = globalObject
return <reactContext.Provider value={pageContext}>{children}</reactContext.Provider>
}
Expand All @@ -24,9 +22,5 @@ function PageContextProvider({ pageContext, children }: { pageContext: PageConte
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.
if (!pageContext) throw new Error('<PageContextProvider> is needed for being able to use usePageContext()')
*/
assert(pageContext)
return pageContext
}
6 changes: 0 additions & 6 deletions packages/vike-react/src/utils/assert.ts

This file was deleted.

0 comments on commit 2cc16cf

Please sign in to comment.