Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeView does not update on items changed #10

Open
bostefan opened this issue Dec 4, 2018 · 0 comments
Open

TreeView does not update on items changed #10

bostefan opened this issue Dec 4, 2018 · 0 comments

Comments

@bostefan
Copy link

bostefan commented Dec 4, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant