helfi92 / material-ui-treeview

A React tree view for material-ui.
MIT License
47 stars 21 forks source link

Not re-rendering #18

Closed bnsv-mayank closed 6 years ago

bnsv-mayank commented 6 years ago

I used this component to get a tree view for all of my data. However, when the props are updated, it seems like the component is not re-rendering and hence the page is not updated. I can confirm that the props passed are being updated because I'm printing them.

helfi92 commented 6 years ago

What kind of prop are you changing? If the prop that is changing is an object, then you'll have to make sure you're passing a "new" object. The component will not update if the reference of the prop is the same.

bnsv-mayank commented 6 years ago

Hey, I'm changing the tree (which is an array). Basically, I have an object: BigTree which contains 4 arrays: smallTree1..smallTree4. I'm passing BigTree[smallTree(x)] where x is decided by user. Could you explain why this is not re-rendering the component? This information goes inside "tree" prop. I'm not using any other props.

helfi92 commented 6 years ago

I will try to look into this tonight or tomorrow. I will get back to you soon :)

bnsv-mayank commented 6 years ago

Thanks. I have tried a lot of things and nothing seems to work. It does re-render but only when an array with string is passed to tree. If I pass an array of objects, the problem comes back.

helfi92 commented 6 years ago

Good to know, will help me debug this faster :)

bnsv-mayank commented 6 years ago

I'll be waiting. My code heavily depends on your library so I hope it gets fixed.

helfi92 commented 6 years ago

Fixed in v2.0.1 🎉

helfi92 commented 6 years ago

https://codesandbox.io/s/50ryzk04jn

bnsv-mayank commented 6 years ago

Hey, it works! I have a question tho. Can we add any other property in the objects present in the tree array? I mean that we are allowed value and nodes, so is it possible to add our own defined attribute?

helfi92 commented 6 years ago

Hm, what are you trying to do?

bnsv-mayank commented 6 years ago

Basically, I want to pass a icon to the value prop in tree. However, it seems like value can only accept strings. Is there any work around?

helfi92 commented 6 years ago

Ah, there's currently no way. We should probably add a new field icon in a tree node. I created https://github.com/helfi92/material-ui-treeview/issues/20. Feel free to take it if you want to give it a shot.