iannbing / react-simple-tree-menu

A simple React tree menu component
MIT License
137 stars 48 forks source link

initialOpenNodes is not updated on re-render of the component #174

Open ashik-jyothi opened 3 years ago

ashik-jyothi commented 3 years ago

I am trying to keep the first node to be open when my component renders but the data is still not available at the point (initialOpenNodes={['']}) as it is fetched via API. Once the data is fetched, TreeMenu renders again with the required data (initialOpenNodes={['<node_name'>']}) but it is not taking the updated prop. I tested this by hardcoding the value and it works fine. So, I assume that the value set on first render is what TreeMenu consumes ignoring the subsequent renders. Even tried with resetOpenNodesOnDataUpdate prop set to true.

Can you please look into this?

iannbing commented 3 years ago

I tried to reproduce the issue, but it seems working fine in this sandbox.

I think you probably only update initialOpenNodes without updating data (i.e. commenting out line 77-91 in the sandbox example). Then, indeed initialOpenNodes is only updated when data is also updated.