zenoamaro / react-quill

A Quill component for React.
https://zenoamaro.github.io/react-quill
MIT License
6.76k stars 921 forks source link

ReactQuill component not appearing in NextJS 13.4.2 #897

Open gurbaaz27 opened 1 year ago

gurbaaz27 commented 1 year ago

Having an issue with ReactQuill component not appearing in NextJS project using React-Quill v2.0.0, NextJS v13.4.2. After Loading, no component for Quill Editor renders on the screen, and it is surprising me.

Any help would be appreciated.

image

Code

'use client'

import dynamic from "next/dynamic"
import { FieldErrors } from "react-hook-form"

const QuillNoSSRWrapper = dynamic(import('react-quill'), {
    ssr: false,
    loading: () => <p>Loading ...</p>,
})
import 'react-quill/dist/quill.snow.css'

interface QuillEditorProps {
    id: string
    placeholder: string
    onChange: (arg0: string) => void
    value: string
    errors: FieldErrors
}

const modules = {
    toolbar: [
        [{ header: '1' }, { header: '2' }, { header: '3' }, { font: [] }],
        [{ size: [] }],
        ['bold', 'italic', 'underline', 'strike', 'blockquote'],
        [
            { list: 'ordered' },
            { list: 'bullet' },
            { indent: '-1' },
            { indent: '+1' },
        ],
        ['link'],
        ['clean'],
    ],
    clipboard: {
        // toggle to add extra line breaks when pasting HTML:
        matchVisual: false,
    },
}

const formats = [
    'header',
    'bold', 'italic', 'underline', 'strike', 'blockquote',
    'list', 'bullet', 'indent',
    'link'
]

const QuillEditor: React.FC<QuillEditorProps> = ({
    id,
    placeholder,
    onChange,
    value,
    errors
}) => {
    return (
        <div className='w-full relative block'>
            <QuillNoSSRWrapper
                theme="snow"
                placeholder={placeholder}
                defaultValue={value}
                value={value}
                onChange={(value) => onChange(value)}
                modules={modules}
                formats={formats}
            />
            {errors[id] ? (
                <p className="mt-2 text-pink-600 text-sm">
                    {errors[id]?.message?.toString()}
                </p>
            ) : <></>}
        </div>
    )
}

export default QuillEditor
sohaibMan commented 1 year ago

did you find a solution ?

gurbaaz27 commented 1 year ago

Nope, hence switched to https://mantine.dev/others/tiptap/ instead.

moussaab-moulim commented 1 year ago

i have the same problem i need to refresh the page every time for the editor to render

sohaibMan commented 1 year ago

is that in the app directory or the old pages directory?

yakkhasuraj commented 1 year ago

I had the same issue. Then I tried importing ReactQuill without lazy loading it worked for me. Instead of this const Quill = dynamic(import(react-quill), { ssr: false, loading: () => <p>Loading ...</p>, });

Try this import Quill from 'react-quill';

sohaibMan commented 1 year ago

I had the same issue. Then I tried importing ReactQuill without lazy loading it worked for me. Instead of this const Quill = dynamic(import(react-quill), { ssr: false, loading: () => <p>Loading ...</p>, });

Try this import Quill from 'react-quill';

is it working in the app directory?

yakkhasuraj commented 1 year ago

I had the same issue. Then I tried importing ReactQuill without lazy loading it worked for me. Instead of this const Quill = dynamic(import(react-quill), { ssr: false, loading: () => <p>Loading ...</p>, }); Try this import Quill from 'react-quill';

is it working in the app directory?

Yes it's working in the app directory

quang13 commented 1 year ago

I have previously solved the following: ` import dynamic from "next/dynamic"

const QuillNoSSRWrapper = dynamic( async () => { const { default: RQ } = await import("react-quill") // eslint-disable-next-line react/display-name return ({ forwardedRef, ...props }) => <RQ ref={forwardedRef} {...props} /> }, { ssr: false, } )

export const QuillToolbar = () => (