Eri*_*ric 4 javascript ckeditor reactjs next.js
我有以下问题:
未处理的运行时错误错误:元素类型无效:需要字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。您可能忘记从定义它的文件中导出组件,或者您可能混淆了默认导入和命名导入。检查 的渲染方法
Resumos
。
这些不同的解决方案不起作用:
解决方案一:
import dynamic from "next/dynamic";
const { CKEditor } = dynamic(
() => {
return import('@ckeditor/ckeditor5-react');
},
{ ssr: false }
);
const {ClassicEditor} = dynamic(
() => {
return import('@ckeditor/ckeditor5-build-classic');
},
{ ssr: false }
);
const Resumos = ({id}) => {
<CKEditor
editor={ ClassicEditor }
data={textoResumoAluno}
onChange={handleChangeTextoResumoAluno}
/>
}
Run Code Online (Sandbox Code Playgroud)
解决方案2:
const Resumos = ({id}) => {
const editorRef = useRef()
const [ editorLoaded, setEditorLoaded ] = useState( false )
const { CKEditor, ClassicEditor } = editorRef.current || {}
useEffect( () => {
editorRef.current = {
CKEditor: require( '@ckeditor/ckeditor5-react' ),
ClassicEditor: require( '@ckeditor/ckeditor5-build-classic' )
}
setEditorLoaded( true )
}, [] );
{editorLoaded ? (
<CKEditor
editor={ ClassicEditor }
data={textoResumoAluno}
onInit={ editor => { /*You can store the "editor" and use when it is needed.
console.log('Editor is ready to use!', editor)*/
}}
onChange={handleChangeTextoResumoAluno}
/>
) : (
<div>Editor loading</div>
)}
}
Run Code Online (Sandbox Code Playgroud)
Eri*_*ric 11
感谢@EstusFlask,它帮助我找到了解决方案!
const Resumos = () => {
const editorRef = useRef()
const [ editorLoaded, setEditorLoaded ] = useState( false )
const { CKEditor, ClassicEditor} = editorRef.current || {}
useEffect( () => {
editorRef.current = {
CKEditor: require( '@ckeditor/ckeditor5-react' ).CKEditor, //Added .CKEditor
ClassicEditor: require( '@ckeditor/ckeditor5-build-classic' ),
}
setEditorLoaded( true )
}, [] );
const [data, setData] = useState('');
return(
<>
{editorLoaded ? <CKEditor
editor={ ClassicEditor }
data={data}
onReady={ editor => {
// You can store the "editor" and use when it is needed.
console.log('Editor is ready to use!', editor);
} }
onChange={ (event, editor ) => {
const data = editor.getData()
setData(data);
} }
/> : <p>Carregando...</p>}
</>
)
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6996 次 |
最近记录: |