我正在尝试将Quill编辑器添加到我的Next.js项目中,并带有History模块(撤消和重做按钮)。我必须使用动态导入,否则,我会得到一个错误,即文档未定义。
下面是我的代码。这是可行的,但我有两个问题:
1.撤消/重做按钮的图标丢失。有一些例子,人们做icons = ReactQuill.Quill.import("ui/icons");
,然后分配自定义图标,但我如何访问ReactQuill.Quill与动态导入?
1.当我尝试为“撤消”和“重做”或任何其他按钮添加自定义处理程序时,编辑器从页面中消失,控制台中没有显示任何错误
import dynamic from "next/dynamic";
const ReactQuill = dynamic(
async () => {
const { default: RQ } = await import("react-quill");
return ({ forwardedRef, ...props }) => <RQ ref={forwardedRef} {...props} />;
},
{
ssr: false,
}
);
import showdown from "showdown";
import "react-quill/dist/quill.snow.css";
import { useState, useEffect, useRef } from "react";
import React from "react";
import styles from "./Editor.module.css";
const converter = new showdown.Converter();
export default function Editor({ title, body = "" }) {
const quillRef = useRef(false);
const text = title ? "# " + title + "\n\n" + body : body;
const initialHtml = converter.makeHtml(text);
const [html, setHtml] = useState(initialHtml);
return (
<ReactQuill
forwardedRef={quillRef}
theme="snow"
value={html}
onChange={setHtml}
modules={{
history: {
delay: 2000,
maxStack: 300,
userOnly: true,
},
toolbar: {
container: [
[{ header: [1, 2, 3, 4, 5, 6, false] }],
["bold", "italic", "underline"],
[{ list: "ordered" }, { list: "bullet" }],
["link"],
["undo", "redo", "image"],
],
handlers: {},
},
}}
/>
);
}
1条答案
按热度按时间flmtquvp1#
发布工作代码,以防有人遇到同样的问题。