Skip to content

Commit

Permalink
fix: 修复初始化页面两次出发bbox问题
Browse files Browse the repository at this point in the history
  • Loading branch information
syb01094648 committed Oct 23, 2023
1 parent 397dfb2 commit 1185258
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/components/geojson-editor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useDebounceEffect, useMount, useSize } from 'ahooks';
import { useDebounce, useMount, useSize, useUpdateEffect } from 'ahooks';
import type { editor } from 'monaco-editor';
import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api';
import React, {
Expand Down Expand Up @@ -32,6 +32,7 @@ export const GeoJsonEditor: React.FC<EditorProps> = forwardRef((props, ref) => {
const { width = 0, height = 0 } = useSize(container) ?? {};
const styles = useStyle();
const [editorTextChange, setEditorTextChange] = useState('');
const debouncedValue = useDebounce(editorTextChange, { wait: 2000 });
const { t } = useTranslation();

// document format
Expand Down Expand Up @@ -113,16 +114,12 @@ export const GeoJsonEditor: React.FC<EditorProps> = forwardRef((props, ref) => {
[scriptContent, t],
);

useDebounceEffect(
() => {
const features = saveEditorText();
if (autoFitBounds) {
bboxAutoFit(features);
}
},
[editorTextChange],
{ wait: 2000 },
);
useUpdateEffect(() => {
const features = saveEditorText();
if (autoFitBounds) {
bboxAutoFit(features);
}
}, [debouncedValue]);

const value = useMemo(() => {
if (language === 'javascript') {
Expand Down

0 comments on commit 1185258

Please sign in to comment.