我遇到了一个有趣的问题。我使用 NextJS 来实现其服务器端渲染功能,并使用 ReactQuill 作为我的富文本编辑器。为了绕过 ReactQuill 与 DOM 的联系,我动态导入它。然而,这提出了另一个问题,即当我尝试将引用附加到 ReactQuill 组件时,它被视为可加载组件而不是 ReactQuill 组件。我需要参考来自定义图像上传到富文本编辑器时的处理方式。现在, ref 返回 current:null 而不是我可以使用 .getEditor() 来自定义图像处理的函数。
有人对我如何解决这个问题有任何想法吗?我尝试了引用转发,但它仍然将引用应用于可加载组件,而不是 React-Quill 组件。这是我的代码的快照。
const ReactQuill = dynamic(import('react-quill'), { ssr: false, loading: () => <p>Loading ...</p> }
);
const ForwardedRefComponent = React.forwardRef((props, ref) => {return (
<ReactQuill {...props} forwardedRef={(el) => {ref = el;}} />
)})
class Create extends Component {
constructor() {
super();
this.reactQuillRef = React.createRef();
}
imageHandler = () => {
console.log(this.reactQuillRef); //this returns current:null, can't use getEditor() on it.
} …Run Code Online (Sandbox Code Playgroud)