तो मैं सिर्फ एक रूपरेखा प्रतिक्रिया से स्रोत कोड डाउनलोड किया है, और मैं टर्मिनल में इस त्रुटि हो रही है:कन्स्ट्रक्टर के बाहर एक प्रतिक्रिया घटक का राज्य क्यों सेट करें?
ERROR in ./src/components/TextEditor.js
Module build failed: SyntaxError: Unexpected token (24:8)
22 |
23 | // Set the initial state when the app is first constructed.
> 24 | state = {
| ^
25 | state: initialState
26 | }
27 |
मेरा प्रश्न है, क्यों लोग एक इस तरह घटक के राज्य प्रतिक्रिया सेट करूँ? अगर कुछ लोगों के लिए यह त्रुटि होगी तो क्या फायदा है? साथ ही, क्या इस त्रुटि को रोकने के लिए कोई बैबेल प्रीसेट या प्लगइन है?
// Import React!
import React from 'react'
import {Editor, Raw} from 'slate'
const initialState = Raw.deserialize({
nodes: [
{
kind: 'block',
type: 'paragraph',
nodes: [
{
kind: 'text',
text: 'A line of text in a paragraph.'
}
]
}
]
}, { terse: true })
// Define our app...
export default class TextEditor extends React.Component {
// Set the initial state when the app is first constructed.
state = {
state: initialState
}
// On change, update the app's React state with the new editor state.
render() {
return (
<Editor
state={this.state.state}
onChange={state => this.setState({ state })}
/>
)
}
}