1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 18:39:51 +02:00

Fix typescript docs (#4303)

* Add docs on annotations for useState and initial editor value

* Typescript docs: Use initialValue
This commit is contained in:
Coury Ditch
2021-07-08 22:50:13 -04:00
committed by GitHub
parent 03e8230196
commit 03eed53cf1
2 changed files with 45 additions and 6 deletions

View File

@@ -47,10 +47,10 @@ const App = () => {
Of course we haven't rendered anything, so you won't see any changes.
> If you are using TypeScript, you will also need to extend the `Editor` with `ReactEditor` as per the documentation on [TypeScript](../concepts/12-typescript.md). The example below also includes the custom types required for the rest of this example.
> If you are using TypeScript, you will also need to extend the `Editor` with `ReactEditor` and add annotations as per the documentation on [TypeScript](../concepts/12-typescript.md). The example below also includes the custom types required for the rest of this example.
```typescript
// TypeScript Users only add this code
// TypeScript users only add this code
import { BaseEditor } from 'slate'
import { ReactEditor } from 'slate-react'
@@ -65,6 +65,14 @@ declare module 'slate' {
}
}
```
```typescript jsx
// Also you must annotate `useState<Descendant[]>` and the editor's initial value.
const App = () => {
const initialValue : CustomElement = [];
const [value, setValue] = useState<Descendant[]>(initialValue)
return <Slate value={value} onChange={setValue}>...</Slate>
}
```
Next we want to create state for `value`: