Skip to content

usePinch without react-spring? #648

Answered by dbismut
bstro asked this question in Q&A
Feb 11, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hi! Sure. react-spring is merely used to animate values outside of react render cycle. Any other animation lib would work, but you could also do something like:

const [x, setX] = useState(0)
const bind = useDrag(({ offset: [x] }) => {
  setX(x)
})

return <div {...bind()} style={{ transform: `translateX(${x}px)` }} />

Note that I would not recommend to do this as it basically re-rerenders the component on every event frame: it's not a major issue with a single div but you'll quickly get into perf issues with a more elaborated situation.

For animation libs, you can have a look at gsap, animate.js. You'll have to manually animate the element as in:

const bind = useDrag(({ target, offset: [x] }

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@bstro
Comment options

Answer selected by bstro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants