diff --git a/packages/react-json-tree/src/JSONNestedNode.tsx b/packages/react-json-tree/src/JSONNestedNode.tsx index 2f035e38..fe82a169 100644 --- a/packages/react-json-tree/src/JSONNestedNode.tsx +++ b/packages/react-json-tree/src/JSONNestedNode.tsx @@ -111,8 +111,9 @@ export default function JSONNestedNode(props: Props) { nodeTypeIndicator, shouldExpandNodeInitially, shouldExpandNode, - styling, + setShouldExpandNode, setEnableDefaultButton, + styling, } = props; const [expanded, setExpanded] = useState( @@ -135,8 +136,9 @@ export default function JSONNestedNode(props: Props) { if (expandable) { setExpanded(!expanded); setEnableDefaultButton(true); + setShouldExpandNode(undefined) } - }, [expandable, expanded, setEnableDefaultButton]); + }, [expandable, expanded, setEnableDefaultButton, setShouldExpandNode]); const renderedChildren = expanded || (hideRoot && level === 0) diff --git a/packages/react-json-tree/src/index.tsx b/packages/react-json-tree/src/index.tsx index 9b5a6d68..9ba8d18b 100644 --- a/packages/react-json-tree/src/index.tsx +++ b/packages/react-json-tree/src/index.tsx @@ -79,6 +79,7 @@ export function JSONTree({ shouldExpandNodeInitially={shouldExpandNodeInitially} shouldExpandNode={shouldExpandNode} setEnableDefaultButton={setEnableDefaultButton} + setShouldExpandNode={setShouldExpandNode} hideRoot={hideRoot} getItemString={getItemString} postprocessValue={postprocessValue} diff --git a/packages/react-json-tree/src/types.ts b/packages/react-json-tree/src/types.ts index 27e4f806..71943a35 100644 --- a/packages/react-json-tree/src/types.ts +++ b/packages/react-json-tree/src/types.ts @@ -54,6 +54,7 @@ export interface CommonExternalProps { collectionLimit: number; sortObjectKeys: SortObjectKeys; setEnableDefaultButton: any; + setShouldExpandNode: any; } export interface CommonInternalProps extends CommonExternalProps {