Hey everyone, just wanted to share this with you. So I've been trying to find rich editors that were compatible with NextJS. Couldn't find any but I found a way to get ReactQuill working.
Import dynamic
import dynamic from 'next/dynamic'
After that import ReactQuill using dynamic
const ReactQuill = dynamic(() => import("react-quill"), { ssr: false });
Now you can easily use it!
Example:
import { useState } from "react";
import dynamic from 'next/dynamic';
const ReactQuill = dynamic(() => import("react-quill"), { ssr: false });
import 'react-quill/dist/quill.snow.css';
function App() {
const [value, setValue] = useState('')
return(
<ReactQuill value={value} onChange={setValue}/>
)
}
export default App;
I hope this helps 😊
Oldest comments (33)
Server Error
TypeError: Quill.register is not a function
This error happened while generating the page. Any console logs will be displayed in the terminal window.
dev-to-uploads.s3.amazonaws.com/up...
dev-to-uploads.s3.amazonaws.com/up...
Can you show me how you imported React-quill?
Did you solution to it?
Thank you! This is very helpful.
thanks you ! this help me lot
How do you import ReactQuill modules (quill-image-resizing -module) on the dynamic imports ?
same pblm
Thank you!! This helped me :)
Thanks a lot! You saved my time!
Arigato Guzaimas
Thank you very much
toolbar is appearing twice. i don't know how to fix it.. i am using quill inside form element
SAme here. Didi you find a solution?
Simple solution, I guess not the best:
I don't think it's the best either, but definitely better than the previous one
Add this CSS in your global style:
.quill > .ql-toolbar:first-child {
display: none !important;
}
Or in your next.config.js
reactStrictMode: false,
can not use ref for image upload handler
ref does not work with dynamic import. you can use this
dynamic import
create ref
const quillRef = useRef(null)
jsx
then in image cllback handler you can now access the quill object and range
const quillObj = quillRef?.current?.getEditor();
const range = quillObj?.getSelection();
then append the image url after upload to the editor's current range
quillObj.editor.insertEmbed(range.index, 'image', data?.secure_url);
here the handler:
Many thanks for this!! ❤️
Getting an error for
forwardedRef
Property 'forwardedRef' does not exist on type '{}'.ts(2339)
Same Issue I am facing @ivanfarkas .Did you got any solution to it.