learnhouse/apps/web/components/Contexts/Editor/EditorContext.tsx
2024-01-14 12:08:39 +01:00

31 lines
711 B
TypeScript

import React, { useState } from 'react'
export const EditorProviderContext = React.createContext(null) as any;
type EditorProviderProps = {
children: React.ReactNode
options: EditorProviderState
}
type EditorProviderState = {
isEditable: boolean
}
function EditorOptionsProvider({ children, options }: EditorProviderProps) {
const [editorOptions, setEditorOptions] = useState<EditorProviderState>(options);
return (
<EditorProviderContext.Provider value={editorOptions}>
{children}
</EditorProviderContext.Provider>
)
}
export default EditorOptionsProvider
export function useEditorProvider() {
return React.useContext(EditorProviderContext);
}