mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-04 21:14:40 -05:00
04900349e6
GitOrigin-RevId: ac305633c7c0bc13f5f670b71890cfd30a3cbffd
34 lines
792 B
TypeScript
34 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>
|
|
)
|
|
}
|