mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
4ca3f9cabf
GitOrigin-RevId: 6b1df81ce588558adab0c31c0f65e68e5b0c25bf
25 lines
693 B
TypeScript
25 lines
693 B
TypeScript
import { createContext, FC, useContext, useState } from 'react'
|
|
import { getMockIde } from './mock/mock-ide'
|
|
|
|
type Ide = {
|
|
[key: string]: any // TODO: define the rest of the `ide` and `$scope` properties
|
|
$scope: Record<string, any>
|
|
}
|
|
|
|
const IdeContext = createContext<Ide | null>(null)
|
|
|
|
export const IdeProvider: FC<{ ide: Ide }> = ({ ide, children }) => {
|
|
const [value] = useState(() => ide || getMockIde())
|
|
|
|
return <IdeContext.Provider value={value}>{children}</IdeContext.Provider>
|
|
}
|
|
|
|
export function useIdeContext(): Ide {
|
|
const context = useContext(IdeContext)
|
|
|
|
if (!context) {
|
|
throw new Error('useIdeContext is only available inside IdeProvider')
|
|
}
|
|
|
|
return context
|
|
}
|