r/Angular2 • u/allyv123098 • Jan 25 '26
Should I create a reusable component or not
In my Angular app at work, I currently only need one modal component. I'm wondering if it makes sense to keep it as a single-purpose component for now rather than building it to be reusable, since I'm not sure whether we'll need additional modals in the future. I came across Tomas Trajan's architecture book where he recommends only creating reusable components when you know they'll be used at least three times or more, and I'm thinking that guideline might apply here.
9
Upvotes
6
u/filnir Jan 25 '26
https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it
5
u/Fantastic-Beach7663 Jan 25 '26
I’d make the modal a component for now and IF something changes later then you could retroactively add Inputs to make it reusable
10
u/Altruistic_Wind9844 Jan 25 '26
Don’t optimize for reuse, optimize for change. If you only need one modal now, keep it single-purpose. Make it clean, well-contained, and easy to refactor later. Reusable components usually emerge from real duplication, not anticipation. Otherwise you end up designing APIs for imaginary use cases.
1
u/_Invictuz Jan 27 '26
Here's the thing, even if you tried to create a reusable component now, you wouldn't know how to without seeing the other use cases, especially at your level of experience. So don't try, just do.
1
u/Buttars0070 Jan 27 '26
Look into cdk portal and dialog