This particular snippet of code showcases a function called Baz:
function Baz({on}) {
const rect1 = <rect x='10' y='10' fill='red' width='10' height='10' />
const rect2 = <rect x='80' y='10' fill='red' width='10' height='10' />
const Rect3 = () => <rect x='10' y='80' fill='red' width='10' height='10' />
const Rect4 = () => <rect x='80' y='80' fill='red' width='10' height='10' />
return (
<svg viewBox="0 0 100 100">
{ on ? rect1 : rect2 }
{ on ? <Rect3 /> : <Rect4 /> }
</svg>
);
}
One interesting behavior here is that the transition from rect1 to rect2 will animate (if css transitions are enabled), while the transition from Rect3 to Rect4 won't.
The question arises: Why does this happen, and are there any potential workarounds?
To better understand this concept, feel free to check out this interactive example on jsfiddle: https://jsfiddle.net/2jLtn39z/