首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误- ReferenceError:文档未定义为NextJS

错误- ReferenceError:文档未定义为NextJS
EN

Stack Overflow用户
提问于 2022-07-20 07:43:47
回答 1查看 296关注 0票数 0

我收到这样一条错误信息

错误- ReferenceError:文档未定义

为什么会这样呢?我从来没有犯过这样的错误,所以我真的很困惑。请帮助那里的高年级学生。

我的代码=

代码语言:javascript
复制
import { useState } from "react";
import dynamic from 'next/dynamic';
import { Quill } from "react-quill";
const ReactQuill = dynamic(() => import("react-quill"), { ssr: false });
import toolbarOptions from "./toolbar";

import 'react-quill/dist/quill.bubble.css';
const BubbleTheme = Quill.import("themes/bubble");

class ExtendBubbleTheme extends BubbleTheme {
  constructor(quill, options) {
    super(quill, options);

    quill.on("selection-change", (range) => {
      if (range) {
        quill.theme.tooltip.show();
        quill.theme.tooltip.position(quill.getBounds(range));
      }
    });
  }
}

Quill.register("themes/bubble", ExtendBubbleTheme);

import styles from '../styles/Home.module.css'

export default function Home() {
  return (
    <div className={styles.container}>
      <h1>Quill Editor</h1>
        <ReactQuill
          theme="bubble"
          placeholder="Compose an epic..."
          modules={{ toolbar: toolbarOptions }}
        />
    </div>
  )
}
EN

回答 1

Stack Overflow用户

发布于 2022-10-17 11:46:42

也遇到了同样的问题。在这个功能组件实现中使用一个下一个动态导入就像一个魅力:

代码语言:javascript
复制
import { useState, useMemo } from "react";
import dynamic from "next/dynamic";

const YourComponent = () => {
  const [value, setValue] = useState("");
  const ReactQuill = useMemo(() => dynamic(() => import('react-quill'), { ssr: false }),[]);

  return (
    <div>
      {/*... */}
      <ReactQuill theme="snow" value={value} onChange={setValue} />
    </div>
  );
};


export default YourComponent;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73047747

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档