01The library was never the plan — it was a decision made once
Every enterprise app I've worked on has migrated its UI library at least once: Material to PrimeNG, or a major version bump that changed component APIs enough to count as a new library. Each time, the pain was directly proportional to how many places in the codebase called that library's components directly.
A thin wrapper (your own Button, DataTable and Modal components that render the third-party ones internally) turns a library swap from "touch every screen" into "rewrite one folder."
02What "thin" means
-
01
Expose your API, not the library's
Your
AppDataTableshould accept props that make sense for your product — not forward every prop PrimeNG's table happens to support. A smaller surface area is what makes a future swap tractable. -
02
Don't rebuild the library inside the wrapper
The wrapper's job is to narrow and translate, not reimplement. If you're writing hundreds of lines per wrapped component, you've built a second library instead of a thin layer.
-
03
Centralize theming inside the wrapper
Design tokens, spacing, and variant props belong in the wrapper's implementation, so a rebrand or dark-mode pass touches one file per component type instead of every usage site.
-
04
Wrap what you use twice, not everything
Wrapping every primitive up front, including ones used once, is wasted effort. Wrap opportunistically. The second time a component pattern repeats is the right time to extract it.
-
05
Enforce the boundary with linting
An ESLint rule banning direct imports from the third-party package outside the wrapper folder turns "please use our wrapper" from a code-review nag into an automatic build failure.
-
06
Version the wrapper's breaking changes deliberately
When the wrapper's own API needs to change, treat it like a real library release, with a changelog entry and a migration note, since dozens of screens now depend on it staying predictable.
03The real payoff isn't the next migration
Teams sometimes skip this because "we're not planning to switch libraries." The wrapper layer pays for itself long before any migration, because it's also where cross-cutting fixes live: the overlay z-index fix, the consistent loading-state pattern, the shared validation message format. Those changes hit one file instead of being copy-pasted across screens by whoever notices the bug first.
A library swap is just the most visible moment the investment shows up. The daily payoff is every smaller fix that didn't need a codebase-wide search-and-replace.
04A wrapper, plus a lint rule to keep it honest
In Angular the wrapper is a small standalone component that exposes your API (typed options, a model() for two-way binding) and passes it to the library underneath. App-wide decisions such as appendTo="body" live there, once.
The boundary only holds if it's enforced. An ESLint no-restricted-imports rule blocks primeng/* everywhere except the shared/ui folder, so a direct library import fails the build instead of waiting for code review.
@Component({
selector: 'app-select',
imports: [Select, FormsModule],
template: `
<p-select [options]="options()" [(ngModel)]="value"
optionLabel="label" optionValue="value"
[placeholder]="placeholder()" appendTo="body" />
`,
})
export class AppSelectComponent<T> {
options = input.required<{ label: string; value: T }[]>();
placeholder = input('Select…');
value = model<T | null>(null);
}
// eslint.config.js
{
files: ['src/app/**/*.ts'],
ignores: ['src/app/shared/ui/**'],
rules: {
'no-restricted-imports': ['error', {
patterns: [{ group: ['primeng/*'], message: 'Use shared/ui wrappers.' }],
}],
},
}
The takeaway
A thin wrapper layer around a UI library — narrow API, centralized theming, enforced by lint rules, built opportunistically rather than up front — turns both library migrations and everyday cross-cutting fixes into one-file changes instead of codebase-wide hunts. Build it the second a component pattern repeats, not after the third library swap teaches you the hard way.