fxmontigny / quill-image-upload

A module for Quill rich text editor to upload images to be selected from toolbar editor.
107 stars 43 forks source link

Using with react-quill got an error #7

Closed murilomothsin closed 5 years ago

murilomothsin commented 5 years ago

Hello,

I'm trying to use your lib with react-quill and I'm getting this error:

The given range isn't in document.

Here's my code snippet:

import React      from 'react'
import ReactQuill, { Quill } from 'react-quill'
import { ImageUpload } from 'quill-image-upload';

Quill.register('modules/imageUpload', ImageUpload);

const QuillEditor = (props) => {
  const defaultHeaderOptions = [2, 3, false]

  return (
    <ReactQuill
      value={props.value}
      onChange={props.onChange}
      theme="bubble"
      modules={{
        toolbar: {
          container: [
           ...
        ]},
        imageUpload: {
          url: '/api/articles/image_upload',
          method: "POST",
          headers: {
            'X-CSRF-TOKEN': document.querySelector('[name="csrf-token"]').content
          },
          callbackOK: (serverResponse, next) => {
            console.log(serverResponse)
            next(serverResponse)
          },
          callbackKO: (serverError) => {
            console.log(serverError);
          },
          checkBeforeSend: (file, next) => {
            console.log(file);
            next(file);
          }
        }
      }}
    />
  )
}

export default QuillEditor

Thanks,

fxmontigny commented 5 years ago

Sorry @murilomothsin i have never use React with quill. This is probably a react error.

Good luck