我正在尝试使用以下代码设置一个简单的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演练中的代码,但是我收到以下错误:
./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} />
这是我第一次使用反应和板岩,我只想感受它。我希望你能帮我解释什么是错的:)
我不知道你是否已经解决了。但是我只是遇到了这个问题,我认为从你的文档中复制它时会有一个剩余的字符。
尝试在块的末尾和注释之间完全删除空白,然后再次将它们添加到您喜欢的位置,它应该可以工作!