gtgalone / react-quilljs

React Hook Wrapper for Quill, powerful rich text editor.
https://www.npmjs.com/package/react-quilljs
MIT License
248 stars 28 forks source link

Best way to import and use Delta? #33

Closed DaltheCow closed 3 years ago

DaltheCow commented 3 years ago

Hey love the repo! This is a question, not sure how to tackle this problem using hooks and react-quilljs. I'd like this to work:

const { quill, quillRef, Quill } = useQuill({ theme, modules, formats });
var Delta = Quill?.import("delta");
const [change, setChange] = React.useState(new Delta());

My problem is that Delta doesn't exist when the initial value is set in the useState. I'd rather not instantiate it as undefined if I can avoid, typescript will make me treat it as if it can be undefined everywhere, but I'm not sure what the best work around would be.

Right now my work around which seems fine is just importing Delta like this: import Delta from "quill-delta";

gtgalone commented 3 years ago

@DaltheCow Thank you for using!

I think quill-delta is a totally separated package with quill.

So you don't have to import delta like this var Delta = Quill?.import("delta");.

If you want to set initial value with delta, you can refer https://github.com/gtgalone/react-quilljs#with-initial-value.