Comments (11)
I’ve commented on that react issue as pointed by Roman in Twitter:
https://twitter.com/roman01la/status/1107695745493356545
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.
Solution is to capture deps in a ref and do the equality check in clojure, pass result to React
from hx.
Fixed via ba0d520
from hx.
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.
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.
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.
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.
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.
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.
(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.
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)
- Destructuring defnc :keys [class] has weird behaviour HOT 1
- Improved react dev-tools support for hooks HOT 3
- Semantics and API of <-state HOT 16
- class & className issue when wrapping defnc component with pure react component HOT 3
- Make it fast
- Experience Report HOT 7
- Reducers dont support Multimethods HOT 4
- Document hiccup parser API
- hx/f exceptions handlint HOT 4
- any HOT 1
- Export hooks under Clojure-style names HOT 2
- `defcomponent` API is very confusing HOT 1
- How-to contains misleading memo use HOT 7
- Push missing tags + maybe a 0.5.4 release HOT 2
- Docstring support for defnc (and defcomponent) HOT 1
- track dependencies to selectively rerender with useMemo HOT 3
- Passing down original js props in render props does not work with js->clj
- hx.hooks/useMemo deps as CLJS collection? HOT 1
- Typo in package 0.5.3 (maybe broken) HOT 3
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 hx.