1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-23 08:50:59 +01:00
slate/site/examples/read-only.js
Ian Storm Taylor f3fc2c2a54
Change <Slate> to a controlled component (#3216)
* change <Slate> to be a controlled component

* add comment about unstable React API
2019-12-05 11:36:44 -05:00

33 lines
791 B
JavaScript

import React, { useState, useMemo } from 'react'
import { createEditor } from 'slate'
import { Slate, Editable, withReact } from 'slate-react'
const ReadOnlyExample = () => {
const [value, setValue] = useState(initialValue)
const [selection, setSelection] = useState(null)
const editor = useMemo(() => withReact(createEditor()), [])
return (
<Slate
editor={editor}
value={value}
selection={selection}
onChange={(value, selection) => {
setValue(value)
setSelection(selection)
}}
>
<Editable readOnly placeholder="Enter some plain text..." />
</Slate>
)
}
const initialValue = [
{
children: [
{ text: 'This is editable plain text, just like a <textarea>!' },
],
},
]
export default ReadOnlyExample