dimanche 5 août 2018

Best practice leads to bloated containers and non modular code

I’ve been told that it’s a best practice to use classes only for containers and to use functions for components. So containers have state and components are dumb functions that only recieve and send props to and from the containers.

The problem I’m finding with this is that it leads to really bloated containers. Not only that but if a container includes many different components then the methods in these containers are a mixture of many different unrelated functionalities.

This goes against the idea of keeping everything very modular. For example if I have a “submit comment” component in my container I would expect the submitCommentHandler method to also be in the relevant component not mixed together in the Post container with a ton of other handlers for unrelated functionalities like being next to the ratePostHandler and the userLoginHandler.

I’m new to react so maybe I’m missing something but how to reconcile this “best practice” with all the other issues it presents?

Aucun commentaire:

Enregistrer un commentaire