Using the proposed React Hooks in ClojureScript



Yesterday at ReactConf, a proposal was introduced for a new React feature called “Hooks.” More info here:

I’m sure I’m not the only one that immediately realized how similar this was to the way reagent components are written :smile:. I personally am perfectly happy to try and get rid of reagent and use (as close to) raw React as possible, and these new features like async rendering, Suspense and (now) Hooks are painting a very bright future for that road.

I decided to whip up a quick demo of it being used in CLJS today:

React-like hooks for reagent

Very nice demo, I like how simply your use-atom brings Clj(s) atom’s and power to React with just a few lines of code. Very nice way of having global state that’s viewed as local state.


I also gave this idea go, but in reagent.
And not actually using react hooks :stuck_out_tongue: (just something that looks a lot like react hooks)

See here

core.clj for usage
hooks.clj for the implementation of the hooks