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 😊
Top comments (33)
Thanks a lot! You saved my time!
Arigato Guzaimas
How do you import ReactQuill modules (quill-image-resizing -module) on the dynamic imports ?
same pblm
Thank you! This is very helpful.
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:
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.
Many thanks for this!! ❤️
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?
i believe , you made a typpo in the beginning of your post
(that library don't exist), instead of
you corrected in your final code
Thank you for noticing. Fixed!
toolbar is appearing twice. i don't know how to fix it.. i am using quill inside form element
Add this CSS in your global style:
.quill > .ql-toolbar:first-child {
display: none !important;
}
Or in your next.config.js
reactStrictMode: false,
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
Thank you!! This helped me :)
const QuillNoSSRWrapper = dynamic(() => import("react-quill"), {
ssr: false,
});
QuillNoSSRWrapper.register("modules/imageResize", ImageResize,);
but I want to register imageResizer it's showing error that imageResizer not exist