Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use extended Editor type in useSlateWithV return type #5763

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading