Last active
March 10, 2023 16:33
-
-
Save arcdev1/aba0fcea9f618de42ca399e3266f42aa to your computer and use it in GitHub Desktop.
A custom React Hook for using CKEditor with SSR particularly with NextJS. https://ckeditor.com | https://nextjs.org
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A custom React Hook for using CKEditor with SSR | |
// particularly with NextJS. | |
// https://ckeditor.com | https://nextjs.org | |
import React, { useRef, useState, useEffect } from 'react' | |
export default function useCKEditor () { | |
const editorRef = useRef() | |
const [isEditorLoaded, setIsEditorLoaded] = useState(false) | |
const { CKEditor, InlineEditor } = editorRef.current || {} | |
useEffect(() => { | |
editorRef.current = { | |
// CKEditor: require('@ckeditor/ckeditor5-react'), // depricated in v3 | |
CKEditor: require('@ckeditor/ckeditor5-react').CKEditor // v3+ | |
InlineEditor: require('@ckeditor/ckeditor5-build-inline') | |
} | |
setIsEditorLoaded(true) | |
}, []) | |
return Object.freeze({ | |
isEditorLoaded, | |
CKEditor, | |
InlineEditor | |
}) | |
} |
getting this error:
Unhandled Runtime Error
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Check the render method of `MyEditor`.
Hey @yelnyaface ... try the updated code above, it seems there was a breaking change in v3.
require is not defined
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So how do we now use this