bobthekingofegypt / dagre-reactjs

React component for rendering a dagre graph layout without any dependency on d3
MIT License
28 stars 8 forks source link

changing style attributes doesn't cause re-render #7

Closed vilterp closed 3 years ago

vilterp commented 3 years ago

Hi there, thanks for this library!

I have a component which is trying to change the background color of a node (via the styles.shapes.styles attribute of the nodes prop to the DagreReact component) as a result of a user selecting a certain node and the component's state updating. It seems that updating attributes like this doesn't cause the graph to re-render — perhaps only changing the set of nodes and edges itself, as in the timeline example.

Ideally changing attributes like background color would re-render, without re-layouting, although I realize it might be difficult to know which attributes changing requires a re-layout. Thanks again!

vilterp commented 3 years ago

Update: after stepping my way into getDerivedStateFromProps, I was able to get it to re-render by incrementing the stage property on each change. So, I'm unblocked, but that is a bit hard to find, and I do wish it was managed automatically somehow… 🤷 Anyway, thanks again for the library.

bobthekingofegypt commented 3 years ago

Hi there, it's been a while since I worked on this project so its not entirely clear in my head. But there is a note at the bottom of the readme about design decisions and there consequences, it seems at some point I decided not to automatically do a react layout on style changes and added stage property to allow you to force it to happen if you need it. It was probably just the easiest option at the time.

vilterp commented 3 years ago

No worries, I was able to get it working.