Someone brought this up on twitter (on the recoil.js thread): https://docs.thi.ng/umbrella/atom/
I’ve been wanting to check out this thing but I always thought it was about graphics etc.
I tried to reimplement use-interval
but my version (which looks like an exact translation to me but there must be some difference) doesn't work, while the original does
original: https://github.com/donavon/use-interval/blob/master/src/index.js#L3
my cljs version: https://github.com/pesterhazy/cljs-scrap/blob/006cdb60eff626cd0b9dfd66cf81c949643371a5/src/main/scrap/scrap.cljs#L13
Browsing on mobile so might miss something. Be careful in useEffect calls to explicitly return undefined.
JS implicitly returns undefined, which React interprets as “nothing to do on unmount”
@orestis that was it!!!!
Does set! Return the value passed in?
@orestis it does indeed
So your callback was called on unmount I guess.
had to add js/undefined
in 2 places: https://github.com/pesterhazy/cljs-scrap/blob/f7fbcfafbfc2e80ccdbee722ff142068d951fd4e/src/main/scrap/scrap.cljs#L13
Let me restate to see if I learned my lesson
If you’re interested in plain React I’d suggest browsing the source of hx and helix. They cover gotchas like this :)
If the fn passed to useEffect returns a value other than undefined, React interprets that in a special way
https://reactjs.org/docs/hooks-reference.html docs aren’t that clear but yes - if you return a function it will be the cleanup function.
If you return something that’s not a function React will complain
hm but it didn't complain
So it’s either undefined or a function
ahh because it happend to be the goddamned callback
You returned a callback,
what a footgun!
😉
An hour lost to debugging but hopefully I'll learn my lesson
Will look into hx as well too!
@orestis :first_place_medal:
Yeah it can be annoying.
I didn't want to start with a lib because I wanted to understand things from the ground up
Note that hx is abandoned and @lilactown is moved to helix these days. I haven’t used the latter which is why I link to hx
I'm looking into using http://recoiljs.org/ with cljs and was going to re-learn hooks to get started
Yeah it’s good to start at the basics.
In this channel we’re mulling over state management stuff
Yeah it's the perennial topic
if you're interested in Recoil this new video (released just yesterday) is a great overview https://www.youtube.com/watch?v=_ISAA_Jt9kI
Yeah I need to finish the last five minutes there. If you go to the zulip mirror you’ll see our discussion here.
it's kind of like Reagent built on top of hooks
ah, which zulip is that?
I’m working on https://github.com/orestis/reseda to explore this topic
ahh sweet, I'm looking into that as well
Uh, the Clojurian zulip? There’s a slack mirror bot which archives messages here.
Note that it’s very much a wip.
ah, thanks, you mean you can look at the zulip to read logs of older messages in this channel?
did y'all already discuss recoil?
I need to figure out how to make a lib that works both with stable and experimental React.
Yep :)
Let me see if there’s a url
I think the channel is named there “slack mirror” and there’s a stream called react which is this channel.
thanks
haha, looks like I'm late to the party 🙂
thanks @aisamu
@pesterhazy the lib I’ve been working on, https://github.com/Lokeh/helix/, provides IME the bare minimum to do ergonomic React programming in CLJS
like orestis was saying :)
it provides as thin of a runtime on top of React as possible, with just a few macros to smooth out the interop with props and elements
it provides easy usage hooks out of the box, as well
@lilactown nice, thanks for the link