I can't seem to find any material on the pros/cons of using a functional component as a container component, now that state isn't an issue.
Edit: This is given that most, if not all container components I've come across are class components. Rephrasing this in the form of a question, given the context of container components, would it be beneficial to use functional components as opposed to container components?
First of all, React Hooks and useState are a very new feature to React (class components were the norm for the last 3 or 4 years, as opposed to a few months for hooks), so most documentation and examples are naturally written using class components.
Second, in my personal experience and as it is written in the official docs, there is really no hurry whatsoever to run away from class container components, especially since a well-written, bug-free code is more important than the most optimized, up-to-date code.
The devs in our company are used to class components for containers (we have a 300,000 LOC React application and 100 million users, so changes are not to come just because yes -- if something breaks we are usually in deep trouble).
And, for now, Class Components allow us to easily answer these questions quickly:
ComponentDidUpdate()ComponentWillUnmount()constructor()I have slowly adopted hooks for personal projects and I really like them, but even after playing with them for a few months, many times I can't come up with a "best practice" way of doing and this has been documented in the docs too: best practices can only come with time.
As for performane, container components are almost never created more than once per page or at most a few times, so I can't possibly think that they would be less performant, provided the code is well written.
Also, benchmarks are mostly just a numbers game (same as CPU cycles and camera mega-pixels), and as posted here by Dan Abramov, seems like benchmarks show similar numbers.
I understand people get obsessed with numbers (when I was really into cameras, I was seriously obsessed with mega-pixels and lens apertures, and funny enough that faded away as my photography skills got better and better).
To sum it up:
if props.fetched !== prevProps.fetched halleluyah!)useReducer and dispatch (the reduction in boiler-plate code, as well as HOCs which I quite dislike is very welcome).Again, this is not by any means the de facto standard or anything, just my personal opinion based on experience. Take what you find useful and leave what you don't. Hope this helps! :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With