Skip to content

Commit 97d4b0c

Browse files
committed
fix view has changed hook
1 parent 8bd3af3 commit 97d4b0c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/compass-crud/src/components/insert-document-dialog.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { without } from 'lodash';
2-
import React, { useCallback, useEffect, useState } from 'react';
2+
import React, { useCallback, useEffect, useRef, useState } from 'react';
33
import type Document from 'hadron-document';
44
import { Element } from 'hadron-document';
55
import {
@@ -200,8 +200,11 @@ const InsertDocumentDialog: React.FC<InsertDocumentDialogProps> = ({
200200
}
201201
}, [isOpen, track]);
202202

203+
const prevJsonView = useRef(jsonView);
203204
useEffect(() => {
204-
if (isOpen && !hasManyDocuments()) {
205+
const viewHasChanged = prevJsonView.current !== jsonView;
206+
prevJsonView.current = jsonView;
207+
if (isOpen && !hasManyDocuments() && viewHasChanged) {
205208
if (!jsonView) {
206209
// When switching to Hadron Document View.
207210
// Reset the invalid elements list, which contains the

0 commit comments

Comments
 (0)