import { useState } from 'react'
import { animated, useTransition } from '@react-spring/web'
import { HomeBlockCopy } from './HomeBlockCopy'
import { useIsomorphicLayoutEffect } from '~/hooks/useIsomorphicEffect'
import { section } from './shared.css'
import clsx from 'clsx'
import { pre } from '../Code/Pre.css'
import { homeBlockCode, list } from './HomeBlockTarget.css'
const webHtml = /* html */ `
import { animated, useSpring } from '@react-spring/web'
export const MyComponent = () => {
const { x } = useSpring({
from: {
x: 0,
},
to: {
x: 1,
},
})
return <animated.div style={{ x }} />
}
`
const nativeHtml = /* html */ `import { animated, useSpring } from '@react-spring/native'
export const MyComponent = () => {
const { x } = useSpring({
from: {
x: 0,
},
to: {
x: 1,
},
})
return <animated.View style={{ x }} />
}
`
const threeHtml = /* html */ `import { animated, useSpring } from '@react-spring/three'
export const MyComponent = () => {
const { x } = useSpring({
from: {
rotateX: 0,
},
to: {
rotateX: Math.PI,
},
})
return <animated.mesh rotate-x={x} />
}
`
const konvaHtml = /* html */ `import { animated, useSpring } from '@react-spring/konva'
export const MyComponent = () => {
const { x } = useSpring({
from: {
x: 0,
},
to: {
x: 1,
},
})
return <animated.Rect x={x} />
}
`
const zdogHtml = /* html */ `import { animated, useSpring } from '@react-spring/zdog'
export const MyComponent = () => {
const { x } = useSpring({
from: {
x: 0,
},
to: {
x: 1,
},
})
return <animated.Ellipse diameter={x} />
}
`
const dataFixtures = [webHtml, nativeHtml, threeHtml, konvaHtml, zdogHtml]
export const HomeBlockTarget = () => {
const [index, setIndex] = useState(0)
const transition = useTransition(index, {
from: {
opacity: 0,
},
enter: {
opacity: 1,
},
leave: {
opacity: 0,
},
config: {
duration: 800,
precision: 0.0001,
},
})
useIsomorphicLayoutEffect(() => {
const interval = setInterval(() => {
setIndex(s => (dataFixtures.length - 1 === s ? 0 : s + 1))
}, 4000)
return () => {
clearInterval(interval)
}
}, [index])
return (
Choose from our five targets:
- web
- native
- three
- konva
- zdog
Missing a target you want? Request we add it or create it yourself
with our advanced API usage.
{transition((style, i) => (
))}
)
}