mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-16 04:04:06 +02:00
docs: Added TypeScript info to the Installing Slate walkthrough
This commit is contained in:
@@ -47,6 +47,25 @@ const App = () => {
|
|||||||
|
|
||||||
Of course we haven't rendered anything, so you won't see any changes.
|
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/11-typescript). The example below also includes the custom types required for the rest of this example.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
// TypeScript Users only add this code
|
||||||
|
import { BaseEditor } from 'slate'
|
||||||
|
import { ReactEditor } from 'slate-react'
|
||||||
|
|
||||||
|
type CustomElement = { type: 'paragraph'; children: CustomText[] }
|
||||||
|
type CustomText = { text: string }
|
||||||
|
|
||||||
|
declare module 'slate' {
|
||||||
|
interface CustomTypes {
|
||||||
|
Editor: BaseEditor & ReactEditor & HistoryEditor
|
||||||
|
Element: CustomElement
|
||||||
|
Text: CustomText
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
Next we want to create state for `value`:
|
Next we want to create state for `value`:
|
||||||
|
|
||||||
```jsx
|
```jsx
|
||||||
|
Reference in New Issue
Block a user