Fork me on GitHub

@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.


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


This won't change how RAtoms work


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


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


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.


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


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


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

💯 4