Skip to content

Commit

Permalink
Use extended Editor type in useSlateWithV return type (#5763)
Browse files Browse the repository at this point in the history
* Use extended `Editor` type in `useSlateWithV` return type

So it matches the return types of `useSlate` and `useSlateStatic`. The
`useSlateWithV` return object's `editor` property is currently typed as
just a `ReactEditor`, which causes type errors in our app when we try to
use it as the extended `Editor` type.

* Fix return types in "Editor hooks" docs
  • Loading branch information
TyMick authored Nov 19, 2024
1 parent 49ba21a commit 644ebdc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/eleven-cycles-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'slate-react': patch
---

Use extended `Editor` type in `useSlateWithV` return type
6 changes: 3 additions & 3 deletions docs/libraries/slate-react/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ Get the current `selected` state of an element.

### Editor hooks

#### `useSlate(): ReactEditor`
#### `useSlate(): Editor`

Get the current editor object from the React context. Re-renders the context whenever changes occur in the editor.

#### `useSlateWithV(): { editor: ReactEditor, v: number }`
#### `useSlateWithV(): { editor: Editor, v: number }`

The same as `useSlate()` but includes a version counter which you can use to prevent re-renders.

#### `useSlateStatic(): ReactEditor`
#### `useSlateStatic(): Editor`

Get the current editor object from the React context. A version of useSlate that does not re-render the context. Previously called `useEditor`.

Expand Down
2 changes: 1 addition & 1 deletion packages/slate-react/src/hooks/use-slate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const useSlate = (): Editor => {
return editor
}

export const useSlateWithV = () => {
export const useSlateWithV = (): { editor: Editor; v: number } => {
const context = useContext(SlateContext)

if (!context) {
Expand Down

0 comments on commit 644ebdc

Please sign in to comment.