ReferenceError: self is not defined while importing CKEditor. I am using next.js.
import { CKEditor } from '@ckeditor/ckeditor5-react';
Already installed using
npm install --save @ckeditor/ckeditor5-react @ckeditor/ckeditor5-build-classic
ReferenceError: self is not defined while importing CKEditor. I am using next.js.
import { CKEditor } from '@ckeditor/ckeditor5-react';
Already installed using
npm install --save @ckeditor/ckeditor5-react @ckeditor/ckeditor5-build-classic
After some trial-and-error I have finally made it work with this setup (NextJS project). No need to alter webpack config. How you handle your input data is up to you.
-MyEditor.jsx
import ClassicEditor from "@ckeditor/ckeditor5-build-classic";
import { CKEditor } from "@ckeditor/ckeditor5-react";
import React from "react";
const Editor = ({
value,
onChange,
}) => {
return (
<CKEditor
editor={ClassicEditor}
data={value}
onChange={(event, editor) => {
const data = editor.getData();
onChange(data);
}}
/>
);
};
export default Editor;
-in any other component:
import dynamic from "next/dynamic";
const MyComp = () => {
const Editor = dynamic(() => import("./MyEditor"), { ssr: false });
return (
<Editor
value={"Foo"}
onChange={(v) => console.log(v)}
/>
)};
onChange
. (onBlur
, onFocus
). And you can access them like in the answer is onChange
–
Ansley © 2022 - 2024 — McMap. All rights reserved.
CKEditor
usingnext/dynamic
withssr: false
to avoid loading it on the server-side, thus preventing the error from occuring. – Urethrectomy