mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
fix(react): useLayoutEffect instead of useEffect to cut down on reflow
This commit is contained in:
parent
942fd07b76
commit
7de99c30c7
5
.changeset/long-pears-wash.md
Normal file
5
.changeset/long-pears-wash.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@tiptap/react": patch
|
||||
---
|
||||
|
||||
This changes useEditorState to use the useLayoutEffect hook instead of the useEffect hook, so that state that might render to the page can be committed in one pass instead of two.
|
@ -1,6 +1,6 @@
|
||||
import type { Editor } from '@tiptap/core'
|
||||
import deepEqual from 'fast-deep-equal/es6/react'
|
||||
import { useDebugValue, useEffect, useState } from 'react'
|
||||
import { useDebugValue, useLayoutEffect, useState } from 'react'
|
||||
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'
|
||||
|
||||
export type EditorStateSnapshot<TEditor extends Editor | null = Editor | null> = {
|
||||
@ -164,7 +164,7 @@ export function useEditorState<TSelectorResult>(
|
||||
options.equalityFn ?? deepEqual,
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
useLayoutEffect(() => {
|
||||
return editorStateManager.watch(options.editor)
|
||||
}, [options.editor, editorStateManager])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user