1

I am attempting to integrate CKEditor into our React.js project, using the component found here: https://github.com/ckeditor/ckeditor5-react.

I have used this code in the git repository to define the CKEditor component:

https://github.com/ckeditor/ckeditor5-react/blob/master/src/ckeditor.jsx

And inside my code, I am referencing the component:

import CKEditor from '@ckeditor/ckeditor5-react';
import ClassicEditor from '@ckeditor/ckeditor5-build-classic';


const TemplateForm = props => {
    return (
        <div>

            /*  Other form fields */

            <CKEditor
                name="body"
                placeholder="Compose message"
                content={ props.defaults.body }
                value={ props.defaults.body }
                errors={ props.errors.body }
                onInput={ props.onInput }
                onChange={ props.onValueChange }
            />

        </div>
    );
};

When I load my page, I get a javascript error "Cannot read property 'create' of undefined" from ckeditor.js - the "this.props.editor" value is not defined. I'm a newbie to react, so I'm sure I'm just missing something pretty straightforward. Suggestions?

1
  • From your error, it seems like the CKEditor is expecting a prop named 'editor' to be passed in. you currently have name, content, value, but not 'editor' Commented Sep 24, 2018 at 18:42

1 Answer 1

4

Your error is from the component (CKEditor) expecting a prop with the key 'editor', which you're not currently supplying.

You can probably find a list of options in their docs, but checking their repo I found this example where they're setting the editor to ClassicEditor which you're already importing:

https://github.com/ckeditor/ckeditor5-react/blob/master/sample/index.html

So this should work:

<CKEditor
  name="body"
  placeholder="Compose message"
  content={ props.defaults.body }
  editor={ ClassicEditor }
  value={ props.defaults.body }
  errors={ props.errors.body }
  onInput={ props.onInput }
  onChange={ props.onValueChange }
/>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much. That fixed my issue - I figured it was something simple. Still trying to wrap my head around react/props/etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.