Skip to content

Instantly share code, notes, and snippets.

@arcdev1
Last active March 10, 2023 16:33
Show Gist options
  • Save arcdev1/aba0fcea9f618de42ca399e3266f42aa to your computer and use it in GitHub Desktop.
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
// 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
})
}
@IRediTOTO
Copy link

Hi, can you show how to add plugin like Alliment to ckeditor ? :s I tried some ways but it not work. It show nothing and text not change when I change heading on menu editor

@esteban89
Copy link

Hi, can you show how to add plugin like Alliment to ckeditor ? :s I tried some ways but it not work. It show nothing and text not change when I change heading on menu editor

Did you find any way to add plugins?

@IRediTOTO
Copy link

Hi, can you show how to add plugin like Alliment to ckeditor ? :s I tried some ways but it not work. It show nothing and text not change when I change heading on menu editor

Did you find any way to add plugins?

I changed to use ckeditor5 :) Its more easy

@javad7z7
Copy link

Hi, can you show how to add plugin like Alliment to ckeditor ? :s I tried some ways but it not work. It show nothing and text not change when I change heading on menu editor

Did you find any way to add plugins?

I changed to use ckeditor5 :) Its more easy

how import plugin in ssr with ckeditor5 ?

@kinghoddy
Copy link

So how do we now use this

@yelnyafacee
Copy link

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`.

@arcdev1
Copy link
Author

arcdev1 commented May 3, 2021

Hey @yelnyaface ... try the updated code above, it seems there was a breaking change in v3.

@divrawat
Copy link

require is not defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment