Skip to content

Commit 946099e

Browse files
committed
refactor: useActiveStyles
1 parent e584a36 commit 946099e

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed
Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { BlockNoteEditor, StyleSchema } from "@blocknote/core";
22

3-
import { useCallback, useState } from "react";
43
import { useBlockNoteContext } from "../editor/BlockNoteContext.js";
5-
import { useEditorChange } from "./useEditorChange.js";
6-
import { useEditorSelectionChange } from "./useEditorSelectionChange.js";
4+
import { useEditorState } from "./useEditorState.js";
75

86
export function useActiveStyles<T extends StyleSchema>(
97
editor?: BlockNoteEditor<any, any, T>,
@@ -19,19 +17,10 @@ export function useActiveStyles<T extends StyleSchema>(
1917
);
2018
}
2119

22-
const e = editor;
23-
24-
const [styles, setStyles] = useState(() => e.getActiveStyles());
25-
26-
const updateStyles = useCallback(() => {
27-
setStyles(e.getActiveStyles());
28-
}, [e]);
29-
30-
// Updates state on editor content change.
31-
useEditorChange(updateStyles, e);
32-
33-
// Updates state on selection change.
34-
useEditorSelectionChange(updateStyles, e);
20+
const styles = useEditorState({
21+
editor,
22+
selector: ({ editor }) => editor.getActiveStyles(),
23+
});
3524

3625
return styles;
3726
}

packages/react/src/hooks/useElementHover.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ export function useElementHover<T = HTMLElement>(
373373
onPointerDown: setPointerRef,
374374
onPointerEnter: setPointerRef,
375375
onMouseMove(event) {
376-
const { nativeEvent } = event;
376+
const nativeEvent = "nativeEvent" in event ? event.nativeEvent : event;
377377

378378
function handleMouseMove() {
379379
if (!blockMouseMoveRef.current && !openRef.current) {

0 commit comments

Comments
 (0)