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:
@@ -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`:
|
||||
|
||||
|
Reference in New Issue
Block a user