Transient Props vs. shouldForwardProp: Which Approach to Adopt for DOM Prop Filtering?
0 reputation · 12 Apr 2021, 21:52 UTC
Goal
To decide on a consistent strategy for filtering custom props that reach underlying DOM elements in a shared React codebase using styled‑components.
Uncertainty
Styled‑components forwards unknown props to HTML tags, causing React warnings, while it forwards all props to custom components. Two documented mechanisms exist: transient props (prefixing with $) and the shouldForwardProp configuration. Each has trade‑offs in API visibility, maintainability, and compatibility across library versions.
Questions
- What are the long‑term maintenance implications of enforcing transient props across a shared codebase?
- Does
shouldForwardPropprovide sufficient flexibility when wrapping third‑party components without leaking props? - How does the choice affect component API consistency and debugging visibility for new developers?