React-spring: lacking documentation: how to pass a spring to animated component

Created on 5 Apr 2020  路  4Comments  路  Source: pmndrs/react-spring

https://www.react-spring.io/docs/hooks/basics says following:

If you want to animate React components, styled-components, or elements on other platforms, then do this:

// React components
const AnimatedDonut = animated(Donut)

Let's assume that I have a following spring definition:

const props = useSpring({opacity: 1, from: {opacity: 0}})

Could you please tell me how to pass the defined spring to the animated component?

question

Most helpful comment

That's because that's only recreating your component to be ready to be animated, you still need to render it.

const props = useSpring({opacity: 1, from: {opacity: 0}})
return (
    <AnimatedDonut style={props}/>
)

Now this is documentation!

Hopefully this info gets to place where it belongs to, instead of being buried here among other issues.

You can submit a PR, it's open source ; )

All 4 comments

Can't see any props passing on this line:

// React components
const AnimatedDonut = animated(Donut)

That's because that's only recreating your component to be ready to be animated, you still need to render it.

const props = useSpring({opacity: 1, from: {opacity: 0}})
return (
    <AnimatedDonut style={props}/>
)

That's because that's only recreating your component to be ready to be animated, you still need to render it.

const props = useSpring({opacity: 1, from: {opacity: 0}})
return (
    <AnimatedDonut style={props}/>
)

Now this is documentation!

Hopefully this info gets to place where it belongs to, instead of being buried here among other issues.

That's because that's only recreating your component to be ready to be animated, you still need to render it.

const props = useSpring({opacity: 1, from: {opacity: 0}})
return (
    <AnimatedDonut style={props}/>
)

Now this is documentation!

Hopefully this info gets to place where it belongs to, instead of being buried here among other issues.

You can submit a PR, it's open source ; )

Was this page helpful?
0 / 5 - 0 ratings