12th week of 2021
No learnings (!), using only custom hooks in React.
Table of contents
Nothing noteworthy this week.
Continued doing Clojure exercises on Exercism.
Nothing to share this week. This is the first time since I started this weekly log.
I have learned quite a lot as I have been learning Clojure. But the things I have learned are so basic that I haven't written them down.
On the other hand, I do think it's a good idea to write down, and preferably also share, even simple and basic stuff. There's just so much stuff I have learned that writing everything down would probably have slowed me down.
As I get better in Clojure, my pace of learning will likely slow down, and maybe I'll then share some nuggets of wisdom. 🧙♂️
Kyle Shevlin's article useEncapsulation raises an interesting guideline: you should use only custom hooks in your React components.
Benefits of this, according to the author:
- Custom hooks encapsulate related elements of a concern and expose APIs for components to use. Thus, custom hooks give more context about what they are related to, and their implementation details don't have to reside inside the component.
- The dependencies of the hooks become obvious because they end up being the arguments of the custom hook functions.
- Custom hooks' implementations can be changed
without changing the components using the hooks.
switching a custom hook to use
useStatemight not require any changes to the consumers (components) of the hook.
I especially like the second point, that the dependencies of the hooks become obvious.
I began writing more thoughts about this, but the text started to become so long that I decided to move my thoughts to a separate blog post. I'll probably publish it next week.