deni-react-treeview icon indicating copy to clipboard operation
deni-react-treeview copied to clipboard

TreeView does not update on items changed

Open bostefan opened this issue 6 years ago • 0 comments

Hi Deni,

We have a use case like so:

A select (combobox) component updates the DeniReactTreeView by setting it's root. On each select, the root becomes the item selected, and we map the children of our model object into the necessary json required by the library. This all works well on:

  1. nothing selected in combobox => select something in combobox
  2. combobox value set => select nothing in combobox This makes the DeniReactTreeView refresh correctly.

However, when passing different set of items to the DeniReactTreeView, and the DeniReactTreeView state already has the rootItem.children set, the behavior is that the DeniReactTreeView is not refreshed although it's state is correct. I traced the problem to lifecycle method componentDidUpdate where after setting the new props.items into the state, it's not refreshed immediately. Or the render does not take into account that the component's root items have changed. Simple this.forceUpdate() did the trick but I think it may not be the best approach.

    key: 'componentDidUpdate',
    value: function componentDidUpdate(prevProps) {
      if (prevProps.items !== this.props.items) {
        this.state.rootItem.children = this.props.items;
        **this.forceUpdate();**
        //treeviewHelper.loadData.call(this, this.props.items);
      }
    }

It seems that the component was never meant to change it's root a lot.

bostefan avatar Dec 04 '18 13:12 bostefan