Hi All
I have a TreeView, the nodes dont seem to call a re render unless the node is selected. Is this the case and if so, can it be altered or are there work arounds?
To replicate, I have created a conditionally rendered functional component as the node item format:
Below is the component that renders each node
const fetchTreeItemView = (props) => {
let item: TreeViewDataItem = props.item;
return (
<>
{(item.selected) &&
<TreeUnselectedEntityNode treeItem={item} />
}
{(!item.selected) &&
<TreeUnselectedEntityNode treeItem={item} />
}
</>
);
};
This calls the below component:
export const TreeUnselectedAttribute = props => {
const [visibleDialog, setVisibleDialog] = React.useState<boolean>(false);
const MENU_ID = `cm-${props.treeItem.index}`;
const { show } = useContextMenu({
id: MENU_ID,
});
const handleClickRemove = (e: React.MouseEvent) => {
show(e);
}
const handleRemoveClick = (e) => {
props.onRemoveTreeItem(props.treeItem);
}
const handleClick = (e) => {
}
const handleClickShowAttributeSelectDialog = (e) => {
setVisibleDialog(true);
}
const hideAttributeSelectDialog = () => {
setVisibleDialog(false);
};
return (
<>
<div>
<div onContextMenu={handleClickRemove}>
<span key="0" /> {props.treeItem.branchXmlNode.name}
</div>
<Menu id={MENU_ID} theme={theme.dark}>
<Item onClick={handleRemoveClick}>Remove</Item>
<Separator />
<Submenu label="Add">
<Item onClick={handleClickShowAttributeSelectDialog}>Attribute</Item>
</Submenu>
</Menu>
{visibleDialog ? <div>Tester</div> : <div>another tester</div>}
</div>
</>
);
}
Its the same component called either way if the node is selected or not, but if the node is selected, when
visibleDialog
is changed, the contents of the div changes (rerenders). if its not selected then no matter how the value of
visibleDialog
is changed, it does not update (rerender)