rnosov / react-reveal

Easily add reveal on scroll animations to your React app
https://www.react-reveal.com/
MIT License
2.73k stars 181 forks source link

How to animate every time a component is shown? #75

Open benlieb opened 5 years ago

benlieb commented 5 years ago

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>
}
jpgutti commented 5 years ago

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

akashraj9828 commented 3 years ago

You can do it using key prop

``

``

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