From 644ebdc8f5f30878fb87dc8685f62e0636c23491 Mon Sep 17 00:00:00 2001 From: Ty Mick <5317080+TyMick@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:14:47 -0800 Subject: [PATCH] Use extended `Editor` type in `useSlateWithV` return type (#5763) * 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 --- .changeset/eleven-cycles-kneel.md | 5 +++++ docs/libraries/slate-react/hooks.md | 6 +++--- packages/slate-react/src/hooks/use-slate.tsx | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .changeset/eleven-cycles-kneel.md diff --git a/.changeset/eleven-cycles-kneel.md b/.changeset/eleven-cycles-kneel.md new file mode 100644 index 000000000..551eea7b7 --- /dev/null +++ b/.changeset/eleven-cycles-kneel.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +Use extended `Editor` type in `useSlateWithV` return type diff --git a/docs/libraries/slate-react/hooks.md b/docs/libraries/slate-react/hooks.md index 358655b60..7dde48dbf 100644 --- a/docs/libraries/slate-react/hooks.md +++ b/docs/libraries/slate-react/hooks.md @@ -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`. diff --git a/packages/slate-react/src/hooks/use-slate.tsx b/packages/slate-react/src/hooks/use-slate.tsx index ff493588c..27e84e771 100644 --- a/packages/slate-react/src/hooks/use-slate.tsx +++ b/packages/slate-react/src/hooks/use-slate.tsx @@ -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) {