Using React Transition Group v2, I want to be able to smoothly transition between an element of text and a loading spinner.
Without any CSSTransitionGroup
element, I have the following code:
{isFetchingEvents ? (
<LoadingSpinner />
) : (
<div>Show More</div>
)}
My initial, and naive, way of approaching this at first would be to use the following:
<CSSTransition
in={isFetchingEvents}
timeout={3000}
classNames="marketGroupFade"
>
<LoadingSpinner />
</CSSTransition>
<CSSTransition
in={!isFetchingEvents}
timeout={3000}
classNames="marketGroupFade"
>
<div>Show More</div>
</CSSTransition>
But this isn't a good solution, because the ternary operator has gone, and repetition of the in
prop is present, as well as repetition of the classNames
. It does transition between the two, but the transition is rough as each component comes in and out.
Is there a neat solution to transitioning between two components that would be rendered in a ternary operator?