This <ErrorBanner/>
component is always rendered, but uses !!error
for the Transition's "in" property. So it animates in when there's an error, and animates out when the error is gone.
However, the error message inside of it also only renders when there's an error. This means the error message unmounts before the banner animates out, so the exiting banner is blank.
Everything that's happening makes complete sense to me. But I'd like to know if there's any way I can show the error as the banner is animating out?
const Wrapper = styled.div({
position: 'absolute',
left: '72px',
right: '460px',
fontSize: TextSizes.Medium,
padding: '24px 36px',
borderRadius: '0 0 12px 12px',
background: colors.componentBackgroundGrey,
transition: '1s ease',
});
const transitionStyles = {
entering: { top: -100 },
entered: { top: 0 },
exiting: { top: 0 },
exited: { top: -100 },
};
const ErrorBanner = ({ error, code }: Props) => (
<Transition in={ !!error } timeout={ 0 }>{ state =>
<Wrapper style={ transitionStyles[state] }>
{ // the message disappears (because it's null) before its container animates out.
error && `ERROR: (${ code }) ${ error.message }`
}
</Wrapper>
}</Transition>
);