I have a button that will change a state from true or false depending on the current state. The text on an element will change when this state changes.
I tried using Transition from 'react-transition-group' because I'm using Emotion styled.
const [animate, setAnimate] = useState(false)
const Heading = styled.h1`
transition: opacity 0.2s;
opacity = ${({state}) => (state === 'entering' || state === 'entered' ? 1 : 0)};
`
return (
<Transition in={animate} timeout={300}>
{state => <Heading state={state}>{animate ? 'Hello' : 'World'}</Heading>}
</Transition>
<button onClick={() => setAnimate(!animate)}>Switch</button>
)
Here, I'm trying to have the 'Hello' text fade out while the 'World' text fades in when the state changes from true to false.