From ed9cb23e413adb07ace7c4acacb4a849ff4a18b4 Mon Sep 17 00:00:00 2001 From: Roman Shtylman Date: Sun, 30 Jan 2022 18:46:24 -0800 Subject: [PATCH] update prop types to allow for optional _circularCache_ and _expandable_ props for JSONNestedNode --- packages/react-json-tree/src/JSONNestedNode.tsx | 8 +++++--- packages/react-json-tree/src/types.ts | 11 +++-------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/react-json-tree/src/JSONNestedNode.tsx b/packages/react-json-tree/src/JSONNestedNode.tsx index 26a8be33..5b05782e 100644 --- a/packages/react-json-tree/src/JSONNestedNode.tsx +++ b/packages/react-json-tree/src/JSONNestedNode.tsx @@ -42,7 +42,7 @@ function renderChildNodes( nodeType, data, collectionLimit, - circularCache, + circularCache = [], keyPath, postprocessValue, sortObjectKeys, @@ -94,10 +94,12 @@ interface Props extends CircularPropsPassedThroughJSONNestedNode { nodeType: string; nodeTypeIndicator: string; createItemString: (data: any, collectionLimit: number) => string; - expandable: boolean; + expandable?: boolean; } export default function JSONNestedNode(props: Props) { + props.circularCache ??= []; + const { getItemString, nodeTypeIndicator, @@ -128,7 +130,7 @@ export default function JSONNestedNode(props: Props) { const renderedChildren = expanded || (hideRoot && props.level === 0) - ? renderChildNodes({ ...props, level: props.level + 1 }) + ? renderChildNodes({ ...props, level: level + 1 }) : null; const itemType = ( diff --git a/packages/react-json-tree/src/types.ts b/packages/react-json-tree/src/types.ts index 5d8e1f7c..3d68c83b 100644 --- a/packages/react-json-tree/src/types.ts +++ b/packages/react-json-tree/src/types.ts @@ -60,22 +60,17 @@ export type CircularPropsPassedThroughJSONNode = JSONValueNodeCircularPropsPassedThroughJSONTree & JSONNestedNodeCircularPropsPassedThroughJSONNode; -export interface JSONNestedNodeCircularPropsPassedThroughJSONNestedNode - extends JSONNestedNodeCircularPropsPassedThroughJSONNode { - circularCache: any[]; - level: number; -} export type CircularPropsPassedThroughJSONNestedNode = SharedCircularPropsProvidedByJSONTree & JSONValueNodeCircularPropsPassedThroughJSONTree & - JSONNestedNodeCircularPropsPassedThroughJSONNestedNode; + JSONNestedNodeCircularPropsPassedThroughJSONNode; export type CircularPropsPassedThroughRenderChildNodes = SharedCircularPropsProvidedByJSONTree & JSONValueNodeCircularPropsPassedThroughJSONTree & - JSONNestedNodeCircularPropsPassedThroughJSONNestedNode; + JSONNestedNodeCircularPropsPassedThroughJSONNode; export type CircularPropsPassedThroughItemRange = SharedCircularPropsProvidedByJSONTree & JSONValueNodeCircularPropsPassedThroughJSONTree & - JSONNestedNodeCircularPropsPassedThroughJSONNestedNode; + JSONNestedNodeCircularPropsPassedThroughJSONNode;