1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-01-18 22:08:18 +01:00
slate/site/examples/read-only.tsx
Wendell Hu 912d4b79da
docs: convert examples to typescript (#3766)
* docs: convert examples to typescript

* docs: convert remaining examples

* docs: update next.js

* ci: fix lint

* docs: fix next.js path

* docs: cleanup

* update

Co-authored-by: wendellhu <wendellhu@tencent.com>
2020-08-19 09:14:51 -07:00

24 lines
640 B
TypeScript

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