Fork me on GitHub
#reagent
<
2020-02-06
>
lispers-anonymous15:02:08

@juhoteperi will hooks allow us to declare an atom and de-ref it in the same function without having to use a form-2 component? In react with javascript hooks can be created and used all within a single functional component.

p-himik16:02:53

You can already do that to some extent with reagent.ratom/with-let.

juhoteperi17:02:51

This won't change how RAtoms work

lispers-anonymous17:02:04

Word. I was just curious. Thanks for the reply and for the work you do on reagent.

juhoteperi17:02:01

Once hooks work, they could probably be used to achieve this by wrapping the atom in one: (let [[state _] (react/useState (r/atom 0))] ...)

juhoteperi17:02:22

State hook would be use to only create the ratom once and then always refer to the same one, RAtom would take care of the updates and triggering re-render.

lispers-anonymous18:02:12

I see what you mean now. I'm guessing we could also use hooks directly with reagent like (let [[state set-state] (react/useState 0)] ... ) one the hooks work is in place? I kind of like the de-ref and swap approach to managing mutable state better but it's cool to have both approaches available

lilactown18:02:55

on first thought, I would expect you would need to get rid of form-2 components because you need to make sure you fire your hooks on every render

juhoteperi19:02:59

You'd use the hooks at the internal fn, which is run every render

💯 4