javascript - 设置 Slate.js
问题描述
我正在尝试使用以下代码设置一个简单的 slate.js 编辑器:
import { Editor } from 'slate-react'
import { Value } from 'slate'
const initialValue = Value.fromJSON({
document: {
nodes: [
{
object: 'block',
type: 'paragraph',
nodes: [
{
object: 'text',
leaves: [
{
text: 'A line of text in a paragraph.',
},
],
},
],
},
],}, });
// Define our app...
class App extends React.Component {
// Set the initial value when the app is first constructed.
state = {
value: initialValue,
};
// On change, update the app's React state with the new editor value.
onChange = ({ value }) => {
this.setState({ value })
} // Render the editor.
render() {
return <Editor value={this.state.value} onChange={this.onChange} />
}
}
export default App
我只是从 slate.js walkthorugh 复制粘贴的代码,但我收到以下错误:
./src/App.js
Syntax error: Unexpected character '' (34:0)
32 | this.setState({ value })
33 | }
> 34 |
| ^
35 | // Render the editor.
36 | render() {
37 | return <Editor value={this.state.value} onChange={this.onChange} />
这是我第一次同时使用 react 和 slate,我只是想感受一下。我希望你能帮我解释什么是错的:)
解决方案
我不知道你是否已经解决了。但我刚刚遇到了这个问题,我认为当你从他们的文档中复制它时,会有一个剩余的字符。
尝试完全删除块末尾和评论之间的空白,然后再次添加它们,它应该可以工作!
推荐阅读
- reactjs - 使用某些道具触发 useEffect() React hook,但在效果中引用其他道具
- c++ - 映射二维数组以进行寻路的最佳方法?
- python - 使用 % 运算符在 python 中打印浮点数
- php - 在 Wordpress 网站上引用 MYSQL 数据库中的数据
- amazon-web-services - 从 Github 获取 AWS CodeDeploy 到 Auto Scale Group 的最新提交
- javascript - 过渡属性的跳跃行为
- java - 条形图左右移动
- linux - 构建内核模块时如何链接静态库?
- laravel - 添加修订后自动更改状态
- python-3.x - 我想从文本输入中提取第三行