When I first heard about ClojureScript, I looked at it through the lens of my JavaScript experience. I assumed it would be like CoffeeScript, you pretty much know the JavaScript you are generating, but now you get to type less. With ClojureScript there’s a gap between the code I write and the code that’s generated, and this gap provides powerful leverage.

I’ve often felt the ClojureScript community should seek to understand and exploit React better. Too many times, by trying to make React easier and more convenient, most ClojureScript libraries obscure many of its important features.

For example, most ClojureScript-based React wrappers try very hard to avoid classes, replacing the many React lifecycle methods with a single render function. Sometimes, this is sufficient but in many situations it’s unhelpful.

This subtle act of wrapping classes results in libraries inventing novel mechanisms to provide access to the React lifecycle methods. In reframing the object oriented paradigm of React into a functional programming one, some complexities are introduced.

Fortunately, React now has a feature that lets us eliminate this complexity. This new feature is called hooks.

Hooks allow you to use plain functions as components, even if they need to utilize lifecycle methods (e.g. for state). ClojureScript library authors no longer need to invent function-based wrappers on React, they can simply use hooks.

There are already plenty of examples of where hooks can lead to simpler code.

Using hooks directly in functions rather than wrapping with custom mechanisms means the work of the large JavaScript community is more accessible than before. The community is already hard at work creating new hooks.