react-arborist
react-arborist copied to clipboard
Add some getter for the "open" property of each node
The open
property (well, collapsed
actually) is part of my controlled data.
I want it to be like this so that the open or closed state is persistent.
I've tried using the onToggle property to keep my open state in sync with react-arborist's open, and it seems to work fine. The problem is that with the initial state they become desynchronized. openByDefault
to true or false would not solve my problem, because some nodes should be able to be initialized open and others closed.
Two ideas have occurred to me:
- Add an
openAccessor
orgetOpen
prop that works as a getter and useonToggle
as a setter. - Add two properties
getOpen
andsetOpen
. It probably makes sense to deprecateonToggle
in this case.
Something I don't like about onToggle
is that instead of passing the node, it passes the id, and I have to do a lookup of my data to find it and access it.
Edit: I just discovered the initialOpenState
property that I had overlooked.
With this I have been able to solve it, although it is a bit of a boilerplate since I have to go through my entire data structure and form an OpenMap
, not ideal.