From bed5e8034db34cafaf5e18261f7b107ed201a894 Mon Sep 17 00:00:00 2001 From: Bo Date: Sat, 22 Jul 2023 07:00:43 +0800 Subject: [PATCH] fix(react-codemirror): unexpected effect called when extension is null (#542) --- core/src/useCodeMirror.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/useCodeMirror.ts b/core/src/useCodeMirror.ts index 367a228a0..3c9a70a0b 100644 --- a/core/src/useCodeMirror.ts +++ b/core/src/useCodeMirror.ts @@ -1,5 +1,5 @@ import { useEffect, useState } from 'react'; -import { Annotation, EditorState, StateEffect } from '@codemirror/state'; +import { Annotation, EditorState, StateEffect, type Extension } from '@codemirror/state'; import { EditorView, ViewUpdate } from '@codemirror/view'; import { getDefaultExtensions } from './getDefaultExtensions'; import { getStatistics } from './utils'; @@ -11,6 +11,8 @@ export interface UseCodeMirror extends ReactCodeMirrorProps { container?: HTMLDivElement | null; } +const emptyExtensions: Extension[] = []; + export function useCodeMirror(props: UseCodeMirror) { const { value, @@ -19,7 +21,7 @@ export function useCodeMirror(props: UseCodeMirror) { onStatistics, onCreateEditor, onUpdate, - extensions = [], + extensions = emptyExtensions, autoFocus, theme = 'light', height = '',