MCPcopy
hub / github.com/pmndrs/react-spring / App

Function App

demo/src/sandboxes/exit-before-enter/src/App.tsx:17–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15]
16
17export default function App() {
18 const [activeIndex, setActiveIndex] = React.useState(0)
19 const springApi = useSpringRef()
20
21 const transitions = useTransition(activeIndex, {
22 from: {
23 clipPath: 'polygon(0% 0%, 0% 100%, 0% 100%, 0% 0%)',
24 },
25 enter: {
26 clipPath: 'polygon(0% 0%, 0% 100%, 100% 100%, 100% 0%)',
27 },
28 leave: {
29 clipPath: 'polygon(100% 0%, 100% 100%, 100% 100%, 100% 0%)',
30 },
31 onRest: (_springs, _ctrl, item) => {
32 if (activeIndex === item) {
33 setActiveIndex(activeIndex === IMAGES.length - 1 ? 0 : activeIndex + 1)
34 }
35 },
36 exitBeforeEnter: true,
37 config: {
38 duration: 4000,
39 },
40 delay: 1000,
41 ref: springApi,
42 })
43
44 const springs = useSpring({
45 from: {
46 strokeDashoffset: 120,
47 },
48 to: {
49 strokeDashoffset: 0,
50 },
51 config: {
52 duration: 11000,
53 },
54 loop: true,
55 ref: springApi,
56 })
57
58 React.useLayoutEffect(() => {
59 springApi.start()
60 }, [activeIndex, springApi])
61
62 return (
63 <div className={styles.container}>
64 <div className={styles.container__inner}>
65 {transitions((springs, item) => (
66 <animated.div className={styles.img__container} style={springs}>
67 <img src={IMAGES[item]} />
68 </animated.div>
69 ))}
70 <div className={styles.ticker}>
71 <div />
72 <animated.svg
73 width="40"
74 height="40"

Callers

nothing calls this directly

Calls 4

useSpringRefFunction · 0.85
useTransitionFunction · 0.85
useSpringFunction · 0.85
startMethod · 0.65

Tested by

no test coverage detected