question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'Error : Delta is not a constructor' while using Clipboard in Module

See original GitHub issue

First of all, Great Job.

My goal is to check if any <img> is pasted in the editor. If yes, then I want to call my backend API for the storage of the image and then replace the base64 version of the src with the URL sent by the API (You already know the custom image handling stuff).

I figured that I have to use the clipboard in the Modules for the said task. So here is my starter code for the same: SandBox Link

import React from "react";
import ReactQuill, { Delta } from "react-quill";
import "react-quill/dist/quill.snow.css";

const customImgForPaste = (node, delta) => {
  console.log("The node here : ", node, "  , Delta : ", delta);
  return delta.compose(new Delta().retain(delta.length(), {}));
};

const modules = {
  toolbar: [
    [{ header: "1" }, { header: "2" }, { font: [] }],
    [{ size: [] }],
    ["bold", "italic", "underline", "strike", "blockquote"],
    [
      { list: "ordered" },
      { list: "bullet" },
      { indent: "-1" },
      { indent: "+1" }
    ],
    ["link", "image", "video"],
    ["clean"]
  ],
  clipboard: {
    matchers: [
            ["img", customImgForPaste]
       ],
  }
};

export default function App() {
  const [text, setText] = React.useState("");

  const onChange = (text) => {
    setText(text);
  };

  return (
    <ReactQuill
      theme="snow"
      placeholder="Type here"
      value={text}
      onChange={onChange}
      modules={modules}
    />
  );
}

But it says Error: Delta is not a constructor. What am I doing wrong? How can I replace the image’s src with the API’s response’s URL? Many thanks.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

2reactions
ncovercashcommented, Jul 23, 2022

@giovannipds try this:

import type { Delta as DeltaType } from "quill";
import ReactQuill, { Quill } from "react-quill";

...

const Delta = Quill.import("delta") as typeof DeltaType;

This will give the Delta the exact same type as the regular quill Delta

2reactions
gatanasocommented, May 31, 2022

Hi @AjayDhimanELS,

You can try the following way of loading Delta:

import ReactQuill, { Quill } from 'react-quill';
const Delta = Quill.import('delta');

BR

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
The JavaScript exception "is not a constructor" occurs when there was an attempt to use an object or a variable as a constructor,...
Read more >
webpack imported module is not a constructor - Stack Overflow
For me, this error was caused by importing through index files. I had multiple directories with their index.ts files that exported all the...
Read more >
When I run this code I got an Typeerror: quickdb is not ... - Reddit
When I run this code I got an Typeerror: quickdb is not a constructor. var express = require('express'); var app = express(); var...
Read more >
Clipboard Module - Quill Rich Text Editor
The Clipboard handles copy, cut and paste between Quill and external ... matcher functions are called with the DOM Node and Delta interpretation...
Read more >
TypeScript style guide - TS.dev
See also export visibility below. Constructors copy link to the clipboard. Constructor calls must use parentheses, even when no arguments are passed: const ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found