import React, { useEffect, useState } from 'react'; import { storiesOf } from '@storybook/react'; import TransitionGroup from '../src/TransitionGroup'; import CSSTransitionGroupFixture from './CSSTransitionGroupFixture'; import NestedTransition from './NestedTransition'; import StoryFixture from './StoryFixture'; import Fade, { FADE_TIMEOUT } from './transitions/CSSFadeForTransitionGroup'; storiesOf('Css Transition Group', module) .add('Animates on all', () => ( )) .add('Animates on enter', () => ( )) .add('Animates on exit', () => ( )) .add('Animates on appear', () => ( )) .add('Dynamic props', () => ( )) .add('Re-entering while leaving', () => ( )) .add('Nested Transitions', () => ); class DynamicTransition extends React.Component { state = { count: 0 }; handleClick = () => { this.setState({ hide: !this.state.hide }); }; componentDidMount() { this.interval = setInterval(() => { this.setState({ count: this.state.count + 1 }); }, 700); } componentWillUnmount() { clearInterval(this.interval); } render() { const { hide, count } = this.state; return (
{!hide && Changing! {count}}
); } } function ReEnterTransition() { const [hide, setHide] = useState(false); useEffect(() => { if (hide) { setTimeout(() => { console.log('re-entering!'); setHide(false); }, 0.5 * FADE_TIMEOUT); } }, [hide]); return (
{!hide && I'm entering!}
); }