Giter Site home page Giter Site logo

Comments (7)

drcmda avatar drcmda commented on May 22, 2024

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.

dbismut avatar dbismut commented on May 22, 2024

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.

drcmda avatar drcmda commented on May 22, 2024

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.

dbismut avatar dbismut commented on May 22, 2024

Oh ok thank you so much! I’ll close this then 👌

from use-gesture.

dbismut avatar dbismut commented on May 22, 2024

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.

drcmda avatar drcmda commented on May 22, 2024

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.

dbismut avatar dbismut commented on May 22, 2024

Right sorry, everything’s crystal clear! Thanks a million.

from use-gesture.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.