1
0
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:
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) { 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)