1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-04-21 13:51:59 +02:00

update saving to a database guide

This commit is contained in:
Ian Storm Taylor 2016-07-18 13:34:45 -07:00
parent c41046ac17
commit dcbca782e5

View File

@ -123,16 +123,17 @@ class App extends React.Component {
constructor(props) {
super(props)
this.state = {
// Update the initial value to be pulled from Local Storage.
state: Plain.deserialize(localStorage.getItem('content'))
}
}
render() {
// Add the `onDocumentChange` handler to the editor.
return (
<Editor
state={this.state.state}
onChange={state => this.onChange(state)}
onDocumentChange={state => this.onDocumentChange(document, state)}
/>
)
}
@ -141,6 +142,7 @@ class App extends React.Component {
this.setState({ state })
}
// Pull the saving logic out into the `onDocumentChange` handler.
onDocumentChange(document, state) {
const string = Plain.serialize(state)
localStorage.setItem('content', string)