简体   繁体   English

设置Slate.js

[英]Setting up Slate.js

I am trying to set up a simple slate.js editor, with the following code: 我正在尝试使用以下代码设置一个简单的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

I simply copy pasted the code from the slate.js walkthorugh, but I get the following error: 我只是从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} />  ./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} /> 

It´s my first time both using react and slate, I just wanted to get a feel for it. 这是我第一次同时使用react和slate,我只是想对此有所了解。 I hope you can help me explaining whats wrong :) 希望您能帮我解释一下问题:)

I don't know if you've solved it already. 我不知道你是否已经解决了。 But I just faced that problem, I think there's a leftover character from when you copied it from their documentation. 但是我只是遇到了这个问题,我认为您从他们的文档中复制时有一个剩余字符。

Try removing the whitespace completely between the end of the block and the comment and then add them to your liking again, it should work! 尝试完全删除块末尾和注释之间的空格,然后再次将它们添加到自己喜欢的位置,这样应该可以!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM