1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-slate/pages/index.js
2018-08-06 21:00:31 -07:00

38 lines
793 B
JavaScript

import React from 'react'
import Plain from 'slate-plain-serializer'
import { Editor } from 'slate-react'
import { KeyUtils } from 'slate'
class Index extends React.Component {
constructor (props) {
super(props)
// In order to allow ssr we need to reset the key
// generating function to its initial state.
KeyUtils.resetGenerator()
// Deserialize the initial editor value.
this.state = {
value: Plain.deserialize(
'This is editable plain text, just like a <textarea>!'
)
}
}
render () {
return (
<Editor
placeholder='Enter some plain text...'
value={this.state.value}
onChange={this.onChange}
/>
)
}
onChange = ({ value }) => {
this.setState({ value })
}
}
export default Index