diff --git a/package.json b/package.json index a290013..0134bf8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "use-prosemirror", - "version": "1.1.3", + "version": "1.1.4", "description": "ProseMirror for React", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/src/ProseMirror.tsx b/src/ProseMirror.tsx index f323ce7..c6c68d2 100644 --- a/src/ProseMirror.tsx +++ b/src/ProseMirror.tsx @@ -31,14 +31,12 @@ export default forwardRef(function ProseMirror( const onChangeRef = useRef(onChange); onChangeRef.current = onChange; const viewRef = useRef>(null!); - viewRef.current?.update(props); + viewRef.current?.update(buildProps(props)); useEffect(() => { - const view = new EditorView(root.current, { - ...initialProps.current, - dispatchTransaction: transaction => { - onChangeRef.current(view.state.apply(transaction)); - }, - }); + const view = new EditorView( + root.current, + buildProps(initialProps.current), + ); viewRef.current = view; return () => { view.destroy(); @@ -50,4 +48,14 @@ export default forwardRef(function ProseMirror( }, })); return
; + function buildProps(props: DirectEditorProps): DirectEditorProps { + return { + ...props, + dispatchTransaction: transaction => { + onChangeRef.current( + viewRef.current.state.apply(transaction), + ); + }, + }; + } });