Comments (7)
This is how hooks work, you never can access hook state in events, it's all stale data. One way to get around this is using useRef, this is also in the hooks docs. Another thing i did today was change how bind works, it's a function now that lets you inject stuff (see frontpage), "transient: true" also isn't needed, just the callback.
from use-gesture.
Thanks @drcmda I'm trying to play with [email protected]
but bind()
returns Object {onMouseDown: undefined, onTouchStart: undefined}
, see here: https://codesandbox.io/s/jpwjzkpqv
Not sure what I'm doing wrong 😬
from use-gesture.
Here's the fixed box: https://codesandbox.io/s/740lo2k9y1
The problem was that you got "interpolate" from react-spring, react-spring/hooks is a separate bundle, so it's gotta be import { interpolate, config, animate, useSpring ........ } from "react-spring/hooks"
But the interpolate function isn't actually needed, you only use it if you interpolate multiple values, so i remove it.
Another thing to watch out for is that in transient mode the event fires immediately, before your count => count + 1
can render out
from use-gesture.
Oh ok thank you so much! I’ll close this then 👌
from use-gesture.
Oops sorry @drcmda one last question: is the Transient component supposed to re-render at every frame of the drag event? I thought the point of transient was to prevent re-rendering?
EDIT: oh and if you could just briefly explain way RAF is needed there that would be great!
from use-gesture.
No, and it doesn't. The log output is from the event handler, the component only renders once per click (because of the set function that is called). You can remove the RAF. Then you will get an outdated count because the click event fires before React renders set(count => count + 1). RAF puts you one frame behind React.
from use-gesture.
Right sorry, everything’s crystal clear! Thanks a million.
from use-gesture.
Related Issues (20)
- Pinch bug: after opening/closing context menu, pinching gesture can be fired with 1 finger HOT 1
- Delegate drag to remaining finger after pinch or support multi-finger drag HOT 5
- Using modifierKey causes the mac pinch event to return HOT 2
- Using pointer.touch cannot be dragged under windows system HOT 6
- useDrag breaks onClick listener in React portal to shadow dom HOT 2
- using video element inside useDrag component doesn't allow the video to play/pause using single click over the video HOT 6
- DragBounds ignored when rerender target HOT 1
- dynamically updating useDrags axis option resets movement : [mx,my] HOT 2
- Using alt+left for navigation prevents all gestures on elements with axis: 'y'
- Drag gesture: Delay setting behavior does not adhere to documentation HOT 4
- Drag + Click + filtertaps option breaks onclick listener. Drag + Click + Treshold works. HOT 1
- touch-action: pan-y prevents L shaped gestures to scroll
- onPinch breaking on control + scroll HOT 5
- Where do I import a3f from? HOT 1
- Getting the error "a3f is not defined"
- Textarea doesn't work inside gesture container HOT 4
- Documentation website is broken (in firefox) HOT 8
- Type error with @types/react >=18.2.66
- (Firefox) Click event fired on drag end
- 100ms delay between pointermove events in Android webviews? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from use-gesture.