zenoamaro / react-quill

A Quill component for React.
https://zenoamaro.github.io/react-quill
MIT License
6.78k stars 923 forks source link

Uncaught (in promise) TypeError: quill.getSelection is not a function Nextjs #977

Open trinhminhhieu opened 6 months ago

trinhminhhieu commented 6 months ago

Hello,I using Nextjs Uncaught (in promise) TypeError: quill.getSelection is not a function Nextjs

here code:

const imageHandler = useCallback(() => {
    const input = document.createElement("input");
    input.setAttribute("type", "file");
    input.setAttribute("accept", "image/*");
    input.click();

    input.onchange = async () => {
      if (input !== null && input.files !== null) {
        const file = input.files[0];
        const url = await uploadImageToServer(file);
        const quill = quillRef.current;
        if (quill) {
          const range = quill.getSelection();
          range && quill.getEditor().insertEmbed(range.index, "image", url);
        }
      }
    };
  }, [quillRef]);

image

GODZ-k commented 6 months ago

what the fuck