Recompose
As soon as we become familiar with HoCs, we realize how powerful they are and how we can get the most out of them.
There is a popular library called recompose which provides many useful HoCs and also a way to compose them nicely.
The HoCs that the library offers are small utilities that we can use to wrap our components, moving away some logic from them and making them more dumb and reusable.
Consider that your component is receiving a user object from an API, and this user object has many attributes.
Letting components receive arbitrary objects is not a good practice because it relies on the fact that the component knows the shape of the object and, most importantly, if the object changes, the component breaks.
A better way for a component to receive props from the parent is to define each single property using primitives.
So, we have a Profile
component to display username
and age
; it looks like this:
const Profile = ({ user }) => ( <div> <div>Username...