File size: 1,370 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
import { Code } from '../Code/Code'
import { HomeBlockCopy } from './HomeBlockCopy'
import { imperativeCode } from './HomeBlockImperative.css'
import { section } from './shared.css'
const example = /* jsx */ `
import { animated, useSpring } from '@react-spring/web'
export default function () {
const [styles, api] = useSpring(
() => ({
x: 0,
rotateZ: 0,
}),
[]
)
const handleClick = () => {
api.start({
to: [
{ x: 200, rotateZ: 360 },
{ x: 0, rotateZ: 0 },
],
})
}
return (
<animated.div
className="spring-box"
onClick={handleClick}
style={{
...styles,
cursor: 'pointer',
}}>
Click Me!
</animated.div>
)
}
`
export const HomeBlockImperative = () => (
<section className={section}>
<HomeBlockCopy
subtitle="Avoid unnecessary overhead"
title={`Run animations without \nre-rendering`}
cta={{
label: 'View imperative API',
href: '/docs/concepts/imperative-api',
}}
>
<p>
Use our imperative API methods to run animations without updating state.
Respond to events without the react rendering overhead to achieve
smooth, fluid animation.
</p>
</HomeBlockCopy>
<Code className={imperativeCode} isLive code={example} showCode={false} />
</section>
)
|