Skip to content

Commit 37e8011

Browse files
committed
Fix crash when switching data sets when search text is present
1 parent a0f0172 commit 37e8011

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/CollectionNode.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,17 @@ export const CollectionNode: React.FC<CollectionNodeProps> = (props) => {
9292
// the animation transition when opening and closing the accordion
9393
const hasBeenOpened = useRef(!startCollapsed)
9494

95+
// DERIVED VALUES (this makes the JSX conditional logic easier to follow
96+
// further down)
97+
const { isEditing, isEditingKey, isArray, canEditKey } = derivedValues
98+
9599
useEffect(() => {
96100
setStringifiedValue(jsonStringify(data))
97101
if (isEditing) setCurrentlyEditingElement(null)
98102
}, [data])
99103

100104
useEffect(() => {
101-
const shouldBeCollapsed = collapseFilter(nodeData) && !derivedValues.isEditing
105+
const shouldBeCollapsed = collapseFilter(nodeData) && !isEditing
102106
hasBeenOpened.current = !shouldBeCollapsed
103107
animateCollapse(shouldBeCollapsed)
104108
}, [collapseFilter])
@@ -235,8 +239,6 @@ export const CollectionNode: React.FC<CollectionNodeProps> = (props) => {
235239
setStringifiedValue(jsonStringify(data))
236240
}
237241

238-
// DERIVED VALUES (this makes the JSX conditional logic easier to follow)
239-
const { isEditing, isEditingKey, isArray, canEditKey } = derivedValues
240242
const showLabel = showArrayIndices || !isArray
241243
const showCount = showCollectionCount === 'when-closed' ? collapsed : showCollectionCount
242244
const showEditButtons = !isEditing && showEditTools

0 commit comments

Comments
 (0)