Skip to content

Commit 3479732

Browse files
authored
fix: editor endless loop (#12)
1 parent afc3531 commit 3479732

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/react/src/WithoutCoreEditor.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,23 @@ export const WithoutCoreEditor = forwardRef<
6767
emits.mounted(shikitor)
6868
}, [ref])
6969

70-
const { vRef: valueRef } = useDefault(value, defaultValue, v => {
70+
const vRefHandle = useCallback((v: string) => {
7171
const shikitor = shikitorRef.current
7272
if (!shikitor) return
7373

7474
shikitor.value = v
75-
})
76-
const { vRef: optionsRef } = useDefault(options, defaultOptions, opts => {
75+
}, [])
76+
77+
const { vRef: valueRef } = useDefault(value, defaultValue, vRefHandle)
78+
79+
const optionRefHandle = useCallback((opts: Omit<ShikitorOptions, "plugins">) => {
7780
const shikitor = shikitorRef.current
7881
if (!shikitor) return
7982

8083
shikitor.updateOptions(old => ({ ...old, ...opts }))
81-
})
84+
}, [])
85+
86+
const { vRef: optionsRef } = useDefault(options, defaultOptions, optionRefHandle)
8287

8388
useEffect(() => {
8489
if (!eleRef.current) return

0 commit comments

Comments
 (0)