react

"mulling over state management stuff"
aisamu 2020-05-16T12:42:21.149600Z

Someone brought this up on twitter (on the recoil.js thread): https://docs.thi.ng/umbrella/atom/

orestis 2020-05-16T13:39:02.150600Z

I’ve been wanting to check out this thing but I always thought it was about graphics etc.

pesterhazy 2020-05-16T13:45:22.151500Z

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

pesterhazy 2020-05-16T13:45:43.151900Z

original: https://github.com/donavon/use-interval/blob/master/src/index.js#L3

orestis 2020-05-16T13:50:49.153500Z

Browsing on mobile so might miss something. Be careful in useEffect calls to explicitly return undefined.

orestis 2020-05-16T13:52:08.154800Z

JS implicitly returns undefined, which React interprets as “nothing to do on unmount”

pesterhazy 2020-05-16T13:54:05.155400Z

@orestis that was it!!!!

orestis 2020-05-16T13:54:27.155900Z

Does set! Return the value passed in?

pesterhazy 2020-05-16T13:55:02.156200Z

@orestis it does indeed

orestis 2020-05-16T13:55:22.156600Z

So your callback was called on unmount I guess.

pesterhazy 2020-05-16T13:56:17.158300Z

Let me restate to see if I learned my lesson

orestis 2020-05-16T13:56:31.159Z

If you’re interested in plain React I’d suggest browsing the source of hx and helix. They cover gotchas like this :)

pesterhazy 2020-05-16T13:56:50.159300Z

If the fn passed to useEffect returns a value other than undefined, React interprets that in a special way

orestis 2020-05-16T13:58:29.160600Z

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.

orestis 2020-05-16T13:59:00.161200Z

If you return something that’s not a function React will complain

pesterhazy 2020-05-16T13:59:10.161700Z

hm but it didn't complain

orestis 2020-05-16T13:59:12.161800Z

So it’s either undefined or a function

pesterhazy 2020-05-16T13:59:24.162400Z

ahh because it happend to be the goddamned callback

orestis 2020-05-16T13:59:29.162700Z

You returned a callback,

pesterhazy 2020-05-16T13:59:31.162900Z

what a footgun!

orestis 2020-05-16T13:59:37.163100Z

😉

pesterhazy 2020-05-16T14:00:05.163600Z

An hour lost to debugging but hopefully I'll learn my lesson

pesterhazy 2020-05-16T14:00:11.163900Z

Will look into hx as well too!

pesterhazy 2020-05-16T14:00:36.164100Z

@orestis :first_place_medal:

orestis 2020-05-16T14:00:49.164400Z

Yeah it can be annoying.

pesterhazy 2020-05-16T14:01:14.165400Z

I didn't want to start with a lib because I wanted to understand things from the ground up

orestis 2020-05-16T14:01:26.165900Z

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

pesterhazy 2020-05-16T14:01:55.166500Z

I'm looking into using http://recoiljs.org/ with cljs and was going to re-learn hooks to get started

orestis 2020-05-16T14:02:00.166700Z

Yeah it’s good to start at the basics.

orestis 2020-05-16T14:02:41.167700Z

In this channel we’re mulling over state management stuff

pesterhazy 2020-05-16T14:02:58.167900Z

Yeah it's the perennial topic

pesterhazy 2020-05-16T14:03:42.168500Z

if you're interested in Recoil this new video (released just yesterday) is a great overview https://www.youtube.com/watch?v=_ISAA_Jt9kI

orestis 2020-05-16T14:04:30.169700Z

Yeah I need to finish the last five minutes there. If you go to the zulip mirror you’ll see our discussion here.

pesterhazy 2020-05-16T14:04:31.169800Z

it's kind of like Reagent built on top of hooks

pesterhazy 2020-05-16T14:04:46.170400Z

ah, which zulip is that?

orestis 2020-05-16T14:04:50.170600Z

I’m working on https://github.com/orestis/reseda to explore this topic

pesterhazy 2020-05-16T14:05:04.171400Z

ahh sweet, I'm looking into that as well

orestis 2020-05-16T14:05:18.171900Z

Uh, the Clojurian zulip? There’s a slack mirror bot which archives messages here.

orestis 2020-05-16T14:05:29.172400Z

Note that it’s very much a wip.

pesterhazy 2020-05-16T14:05:56.173500Z

ah, thanks, you mean you can look at the zulip to read logs of older messages in this channel?

👍 1
pesterhazy 2020-05-16T14:06:04.173900Z

did y'all already discuss recoil?

orestis 2020-05-16T14:06:07.174100Z

I need to figure out how to make a lib that works both with stable and experimental React.

orestis 2020-05-16T14:06:11.174300Z

Yep :)

orestis 2020-05-16T14:06:16.174600Z

Let me see if there’s a url

orestis 2020-05-16T14:06:49.175Z

https://clojurians.zulipchat.com/login/ @pesterhazy

orestis 2020-05-16T14:07:14.176Z

I think the channel is named there “slack mirror” and there’s a stream called react which is this channel.

pesterhazy 2020-05-16T14:08:00.176300Z

thanks

pesterhazy 2020-05-16T14:17:23.177700Z

haha, looks like I'm late to the party 🙂

pesterhazy 2020-05-16T14:18:04.177900Z

thanks @aisamu

lilactown 2020-05-16T16:14:22.179300Z

@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

lilactown 2020-05-16T16:14:35.179700Z

like orestis was saying :)

lilactown 2020-05-16T16:15:35.180800Z

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

lilactown 2020-05-16T16:15:59.181400Z

it provides easy usage hooks out of the box, as well

pesterhazy 2020-05-16T17:21:11.181700Z

@lilactown nice, thanks for the link