簡體   English   中英

設置Slate.js

[英]Setting up 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} />  ./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,我只是想對此有所了解。 希望您能幫我解釋一下問題:)

我不知道你是否已經解決了。 但是我只是遇到了這個問題,我認為您從他們的文檔中復制時有一個剩余字符。

嘗試完全刪除塊末尾和注釋之間的空格,然后再次將它們添加到自己喜歡的位置,這樣應該可以!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM