ton*_*ark 5 javascript node.js angularjs reactjs next.js
当我在 nextjs 项目中使用 jodti-react 时,自我未定义错误
import React, { useState, useRef, useMemo } from "react";
import Dashborad from "./Dashborad";
import JoditEditor from "jodit-react";
import dynamic from "next/dynamic";
export default function edit() {
const editor = useRef();
const [content, setContent] = useState("");
return (
<Dashborad>
<JoditEditor
ref={editor}
value={content}
tabIndex={1} // tabIndex of textarea
onBlur={(newContent) => setContent(newContent)} // preferred to use only this option to update the content for performance reasons
onChange={(newContent) => setContent(newContent)}
/>
</Dashborad>
);
}
Run Code Online (Sandbox Code Playgroud)
}
如何解决这个错误?
创建 jodit.js 文件
import { useRef, useMemo } from 'react'
import JoditEditor from 'jodit-react'
const Jodit = ({ content, setContent }) => {
const editor = useRef(null)
return (
<JoditEditor
ref={editor}
value={content}
tabIndex={1} // tabIndex of textarea
onBlur={(newContent) => setContent(newContent)} // preferred to use only this option to update the content for performance reasons
onChange={(newContent) => setContent(newContent)}
/>
)
}
export default Jodit
Run Code Online (Sandbox Code Playgroud)
使用动态导入
const Jodit = dynamic(() => import('./Jodit'), { ssr: false })
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1159 次 |
| 最近记录: |