Giter VIP home page Giter VIP logo

Comments (11)

orestis avatar orestis commented on July 25, 2024 1

I’ve commented on that react issue as pointed by Roman in Twitter:
https://twitter.com/roman01la/status/1107695745493356545

facebook/react#14476

Some similar efforts to bridge Hooks and ClojureScript are here:
https://github.com/mhuebert/chia/blob/master/view/src/chia/view/hooks.cljs

from hx.

lilactown avatar lilactown commented on July 25, 2024

Solution is to capture deps in a ref and do the equality check in clojure, pass result to React

from hx.

lilactown avatar lilactown commented on July 25, 2024

Fixed via ba0d520

from hx.

orestis avatar orestis commented on July 25, 2024

I was just reading up on this, came to post about it :)

Doesn’t useState have the same issue? React will skip the render if the returned value is the same as the previous one, but it uses the same algorithm.

from hx.

lilactown avatar lilactown commented on July 25, 2024

Ah, I didn’t think to check useState as well. Good call out!

I wonder if there is a good way to handle that... I’m not sure how to do the comparison if the value given to the update function is itself a function to be applied, without doing the computation twice.

And using a ref we might end up creating similar bugs as with atomified <-state.

from hx.

roman01la avatar roman01la commented on July 25, 2024

Hello! Do you have any ideas how this can be fixed for useState? I'm starting to think that Hooks API stands in the way of integrating React with ClojureScript when trying to provide idiomatic Clojure API for library users.

Including @mhuebert in this discussion, since he's working on a wrapper as well.

from hx.

orestis avatar orestis commented on July 25, 2024

I don't have any specific thoughts in mind yet. I am working though on a real-world application that's built entirely on hx, so I'm using that as a real-life place to validate new ideas.

The thing that is really great with hooks though is that the API surface is rather small, so it's easy to write different wrappers and see how they behave. Their composability is what makes me want to keep pushing this, since doing the same with class-based components was pretty much impossible.

from hx.

roman01la avatar roman01la commented on July 25, 2024

Actually I think this is an easy fix for useState, if you wrap the hook you can compare values inside of the wrapper before setting a new value onto the hook roman01la/uix@3665c63

from hx.

orestis avatar orestis commented on July 25, 2024

Yeah, that's the obvious fix. We discussed at length with @Lokeh whether it makes sense to expose the "ref" semantics of atoms, because they can be confusing if you're expecting normal clojure atom behaviour. See #11 (comment)

from hx.

mhuebert avatar mhuebert commented on July 25, 2024
   (when (not= new-value value)
    (set-value new-value))

I was trying to think of values for which Clojure would say not= while Object.is would say true (ie. cases where set-value would be an undesired no-op), but the only thing I could think of is js/NaN, which is probably not an edge case to worry about.

from hx.

orestis avatar orestis commented on July 25, 2024

I think that's a very good point and a test suite could be setup to explore this. If it's only js/NaN then perhaps it's not worth the hassle :)

from hx.

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.