react-reveal icon indicating copy to clipboard operation
react-reveal copied to clipboard

How to animate every time a component is shown?

Open benlieb opened this issue 6 years ago • 2 comments

With the code below, the animation only runs on the first page load, but not when the value of this.state.mode changes, showing the other component.

How can I get the animation to run every time?

{ this.state.mode === 'read'
?
  <Fade>
    <TextComponent />
  </Fade>
:
  <Fade>
    <FormComponent />
  </Fade>
}

benlieb avatar Oct 11 '19 21:10 benlieb

Hey @benlieb , you could try passing the prop spy as the documentation says.

spy: Any change in this prop value will cause the element to be revealed again. It makes sense to set it to some state variable. Disables the initial reveal animation (use appear prop to reenable it).

Something like this:

  <Fade spy={this.state.mode}>
    <TextComponent />
  </Fade>

And every time state.mode change the animation is triggered again

jpgutti avatar Oct 17 '19 17:10 jpgutti

You can do it using key prop

<Fade key={this.state.mode}> <TextComponent /> </Fade>

Every time key changed the component is unmounted and mounted again and will trigger the animation

akashraj9828 avatar Jan 19 '21 05:01 akashraj9828