I'm making a sliding tree navigation component in React.
When going forward the new list slides in from the right, the old one slides out to the left.
I do it with <TransitionGroup> and <CSSTransition>.
I am removing the old list from the array and adding the new one to it, every item is properly keyed. It works.
However when going back it doesn't.
I have a demo here: https://codesandbox.io/s/1wq71p5ly3
When navigating back, in <App> component state I am flipping a boolean value and supply it to <TreeContainer> component so inside <CSSTransition> a different CSS class could be applied (basically reversing the direction of the translate).
When removing and adding from an array (and then setting state) for some reason the <TreeContainer> is called 3 times (I guess one for removal, one for addition and one for... I don't know). This is still fine when navigating forward, but when I go backward as you can see in the demo, I logged the boolean value inside <TreeContainer> after explicitly setting its value inside the parent with setState and this is what I got:
false
true
false
It is still called three times, but once the boolean value is true, even though I set it explicitly to false.
I have no clue why does it work in one direction and why doesn't in the other. It must be some minor thing I am overlooking, but I can't see it. I would really appreciate your help.