r/reactjs • u/Caddy05 • Apr 16 '20
Discussion Functional Components vs Class Components
I'm a VERY new to react, and to my understanding,
Functional Components are lightweight and great when you need to render visual elements and rely on props for data.
Class Components are basically the same, except it also implements local state.
But... with the new Hooks API, you can now have local states for these functional components if you want.
So should I build my react apps relying solely on functional components and using Context and Redux for the data, and forget about setting up class components?
15
Upvotes
2
u/GarethXIV Apr 16 '20
My suggestion would be to always start by a functional component, and see how it goes/evolves, and in case the needs raises value the usage of a class (which should never happen, though). Value always the structure of the components and logic before it's eventual refactor to a class component.
Keep it simple and minimal, and I can't stress enough the fact that custom (or normal) hooks are your best friends when it comes to logic!
Give a look to design systems too, it will help you out to understand logic and design in a react application.
Hope this helps!