Hi Aleksa S., thank you for your comment! This technique may be more suitable for backend development.
If you do use this techinique in the frontend and apply the Single Responsibility Principle, you will not risk importing unused parts of a class, since the class has only one job, and the whole class will be used.
That said, hooks and composition functions are a form of encapsulation, since you're packaging logic in a way that is easy to use AND enforces correct usage at the same time (does not allow incorrect usage).
So, as long as the implementation details are hidden and the function/method/class enforces consistency (i.e. protects the data), you're doing encapsulation, just in different forms.
Aleksa
Aficionado of tech 💻 🚀
Great article, however, I don't think encapsulation is always the solution. Having lots of classes in React/Vue basically nullifies treeshaking, and unused parts of the classes will be bundled up in parts of the code where they are not actually used.
From frontend-only perspective, it is way more performant and intuitive to write hooks/composition functions instead, whether or not you use TS.