diff --git a/packages/react/src/components/TreeView/TreeNode.js b/packages/react/src/components/TreeView/TreeNode.js
index bd5d82aec208..4505f60477de 100644
--- a/packages/react/src/components/TreeView/TreeNode.js
+++ b/packages/react/src/components/TreeView/TreeNode.js
@@ -166,8 +166,8 @@ export default function TreeNode({
}
// sync props and state
- setExpanded(expanded);
- }, [children, depth, expanded, Icon]);
+ setExpanded(isExpanded);
+ }, [children, depth, Icon, isExpanded]);
const treeNodeProps = {
...rest,
diff --git a/packages/react/src/components/TreeView/TreeView-story.js b/packages/react/src/components/TreeView/TreeView-story.js
index 306ff9d2f21a..0cdceff624c0 100644
--- a/packages/react/src/components/TreeView/TreeView-story.js
+++ b/packages/react/src/components/TreeView/TreeView-story.js
@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/
-import React from 'react';
+import React, { useState } from 'react';
import { Document16, Folder16 } from '@carbon/icons-react';
import { action } from '@storybook/addon-actions';
import {
@@ -233,16 +233,17 @@ const nodes = [
},
];
-function renderTree({ nodes, withIcons = false }) {
+function renderTree({ nodes, expanded, withIcons = false }) {
if (!nodes) {
return;
}
- return nodes.map(({ children, renderIcon, ...nodeProps }) => (
+ return nodes.map(({ children, renderIcon, isExpanded, ...nodeProps }) => (