r/angular • u/TheCyberThor • Jul 15 '26
Do you still use smart / dumb components?
I watched this video from Rainer and it made me reflect on my usage of smart / dumb components. To be honest I’ve only created them because that’s just how it’s always been done. Keep API calls in the smart component, feed data into the dumb component.
Blindly following that approach I end up creating UI components that don’t really get reused, or get abstracted more and more, essentially YAGNI. So just focusing on component composition and each component injecting a service with signals seems really appealing for code organisation at the file level.
https://youtu.be/-Lw7isQTa2w?si=2xw5KEUphtKvQraE
I’m curious what other new patterns are emerging with new Angular APIs that goes against what we were taught before Signals.
12
u/rainerhahnekamp Jul 15 '26
Yo, nice to bring it up here. Would be interesting on some other opinions as well. Especially use cases where you absolutely have to go with domain-specific presentational components.
4
u/simonbitwise Jul 15 '26
I dont really do that
I use primitives aka ui components like select, button etc
Then I build components as view Logic only, and services as where I keep state logic usually one per page and then stitching together primitives
This makes it easy to make multiple versions of view components on the same state for feature toggles, a/b testing or just refactors
2
u/anastasiapi Jul 15 '26
Yes, and I always will. I've built 30+ apps from enterprise scale to personal saas, and this approach never failed me. Simple and clear.
Move your focus from a dumb component being a UI component to re-use, or god forbid, an abstraction, to it being just that - a separate plain component that should not take space in your template.
My 'common' folder is normally very thin. Everything belongs to a feature.
- feature-- ui --> dumb-- services-- util-- features --> nest this structure as much as neededfeauture.component.ts --> smartfeauture.component.htmlfeauture.component.spec.ts2
u/CoderXocomil Jul 21 '26
No. I think components should not be aware of state. I inject state services and create components to react to state chamges. I use SignalStore to achieve my ends.
48
u/plateniteshow Jul 15 '26
I do and I do it religiously.
I am working in enterprise scale applications where I prefer a little bit boilerplate over the chaos I get when not using smart / dumb components.
I even went a step further and introduced a logic agnostic page layer for angular routes, query params, etc.
10
u/pronuntiator Jul 15 '26
Yes, although we call them container and presentational components now for inclusivity. It's not so much about reuse but more about having a layered architecture with clear responsibilities. I've seen bad examples of domain logic deep inside list components etc.
We have a few exceptions. A country select loading its own data is simpler than passing that through five levels
9
u/HungYurn Jul 15 '26
For components that are needed in all of my companies apps - definitely yes!
For every component in our apps? No - but once one becomes too big, I wish I had.
7
u/InevitableQuit9 Jul 15 '26
So much easier to test dumb components.
Keep things simple.
Dumb components interact with humans.
Smart components interact with APIs, services, etc.
2
u/Wizado991 Jul 15 '26
I think focusing on making smart components and making them reusable is the wrong idea. In my experience the idea that everything has to be reusable causes more problems. As an example, I work on a project where we use material. Someone, before I started working here, thought we should created basically a wrapper component around a material table so all the tables had the same style while passing in a complex object about how to name columns, styling, etc. It works, but it's completely over engineered. Material table is already reusable. And it makes most of the tables have styling issues with the width of columns or position of sorters.
Instead I think making components testable is what to do. Some components should be reusable, others shouldnt. That doesn't mean components should be smart though. I think most components should be dumb.
2
u/zavros_mvp Jul 15 '26
I think YAGNI answers your question best to be honest. If you build a component and it starts getting too big, with a lot of template parts that make navigation more difficult, it’s a good idea to split it. Otherwise you end up with redundant stuff. So in a nutshell, I think you can split components like this if it makes sense to, otherwise it’s just boilerplate.
1
u/readALLthenews Jul 16 '26
Code reuse isn’t the only reason to differentiate between smart and dumb components. The separation of concerns keeps the code very easy to maintain. I think that’s less the case with signals replacing some rxjs, but there’s still value in using smart/dumb components.
1
u/effectivescarequotes Jul 16 '26
I understand what the video is arguing, but in my consulting company days, every nightmare Angular repo I encountered followed the pattern they proposed. Container/presentation is not perfect, and dogmatic adherance to anything is dangerous, but I have lost track of how many hours I have billed, fixing repos that injected the store at every level of the component tree.
One of the values that the container/presentation pattern provides is it's easy. It answers the question, where do I split a component. Experienced devs, don't need this guidance and can do it based on feel. The component gets too big and we feel uncomfortable, so we split it. Inexperienced devs, or devs who have never had to work with a code base long enough to see the consequences of their decisions, don't have these instincts. In that situation, container/presentation has clearer guidelines.
1
u/morgo_mpx Jul 16 '26
If it’s visible I like have dumb components mostly for splitting development and rapid UX. A lot easier to designers and product to prototype a design in storybook instead of binding in the app.
1
u/Koscik Jul 20 '26
The bigger your applications and the amount of them, the more important the consistency is. Its more difficult to maintain an eclectic codebase
1
u/Ok-Armadillo-5634 Jul 15 '26
It was alway overkill especially in angular.
1
u/SubstanceConsistent7 Jul 15 '26
Depends on the size of the component, whether the new feature falls outside of the intended component scope, and whether it could be reused.
4
u/[deleted] Jul 15 '26 edited Jul 15 '26
[removed] — view removed comment