mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
35 lines
792 B
TypeScript
35 lines
792 B
TypeScript
|
import { createContext, FC, useContext, useMemo, useState } from 'react'
|
||
|
|
||
|
const PdfPreviewContext = createContext<
|
||
|
| {
|
||
|
loadingError: boolean
|
||
|
setLoadingError: (value: boolean) => void
|
||
|
}
|
||
|
| undefined
|
||
|
>(undefined)
|
||
|
|
||
|
export const usePdfPreviewContext = () => {
|
||
|
const context = useContext(PdfPreviewContext)
|
||
|
if (!context) {
|
||
|
throw new Error(
|
||
|
'usePdfPreviewContext is only avalable inside PdfPreviewProvider'
|
||
|
)
|
||
|
}
|
||
|
return context
|
||
|
}
|
||
|
|
||
|
export const PdfPreviewProvider: FC = ({ children }) => {
|
||
|
const [loadingError, setLoadingError] = useState(false)
|
||
|
|
||
|
const value = useMemo(
|
||
|
() => ({ loadingError, setLoadingError }),
|
||
|
[loadingError]
|
||
|
)
|
||
|
|
||
|
return (
|
||
|
<PdfPreviewContext.Provider value={value}>
|
||
|
{children}
|
||
|
</PdfPreviewContext.Provider>
|
||
|
)
|
||
|
}
|