mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-11 01:33:58 +02:00
update saving to a database guide
This commit is contained in:
@@ -123,16 +123,17 @@ class App extends React.Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
// Update the initial value to be pulled from Local Storage.
|
|
||||||
state: Plain.deserialize(localStorage.getItem('content'))
|
state: Plain.deserialize(localStorage.getItem('content'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
// Add the `onDocumentChange` handler to the editor.
|
||||||
return (
|
return (
|
||||||
<Editor
|
<Editor
|
||||||
state={this.state.state}
|
state={this.state.state}
|
||||||
onChange={state => this.onChange(state)}
|
onChange={state => this.onChange(state)}
|
||||||
|
onDocumentChange={state => this.onDocumentChange(document, state)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -141,6 +142,7 @@ class App extends React.Component {
|
|||||||
this.setState({ state })
|
this.setState({ state })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pull the saving logic out into the `onDocumentChange` handler.
|
||||||
onDocumentChange(document, state) {
|
onDocumentChange(document, state) {
|
||||||
const string = Plain.serialize(state)
|
const string = Plain.serialize(state)
|
||||||
localStorage.setItem('content', string)
|
localStorage.setItem('content', string)
|
||||||
|
Reference in New Issue
Block a user