From a13c445a535963aad8e8624b3eb00f385e4cfa74 Mon Sep 17 00:00:00 2001 From: Ty Mick Date: Fri, 8 Nov 2024 10:34:47 -0800 Subject: [PATCH 1/2] 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. --- .changeset/eleven-cycles-kneel.md | 5 +++++ packages/slate-react/src/hooks/use-slate.tsx | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) 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 0000000000..551eea7b7b --- /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/packages/slate-react/src/hooks/use-slate.tsx b/packages/slate-react/src/hooks/use-slate.tsx index ff493588cb..27e84e7713 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) { From 214e939f0bc9a67f34839bfaa95af793c1fc2aa9 Mon Sep 17 00:00:00 2001 From: Ty Mick Date: Fri, 8 Nov 2024 12:04:29 -0800 Subject: [PATCH 2/2] Fix return types in "Editor hooks" docs --- docs/libraries/slate-react/hooks.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/libraries/slate-react/hooks.md b/docs/libraries/slate-react/hooks.md index 358655b607..7dde48dbf3 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`.