ra-input-rich-text
Version:
<RichTextInput> component for react-admin, useful for editing HTML code in admin GUIs.
32 lines (25 loc) • 741 B
text/typescript
import { useContext, useEffect, useState } from 'react';
import { TiptapEditorContext } from './TiptapEditorContext';
export const useTiptapEditor = () => {
const [ready, setReady] = useState(false);
const editor = useContext(TiptapEditorContext);
useEffect(() => {
const onReady = () => {
setReady(true);
};
if (editor != null) {
// This ensure support for hot reload
setReady(editor.isEditable);
editor.on('create', onReady);
}
return () => {
if (editor != null) {
editor.off('create', onReady);
}
};
}, [editor]);
if (ready) {
return editor;
}
return null;
};