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.
The community is already hard at work creating new hooks.
I’ve created a project you can use to experiment with the snippets below yourself.