Closed dcwarwick closed 3 years ago
@dcwarwick I believe the helper uses Component.name
as a fallback but that components that use React.forwardRef
won't have a name
defined (or displayName
). Definitely makes sense to add in displayName
for components that use forwardRef
and this helper 👍
What package(s) are you using?
carbon-components
carbon-components-react
Detailed description
React generates an automatic 'name' for components based on the class name or function name of the render function for hook-based components. However,
React.forwardRef
prevents this being done successfully. When hook-based components useReact.forwardRef
it is helpful to set adisplayName
field on the result so that the component shows up recognisably in dev tools and debugging etc.Some components do set
displayName
, e.g.Button
, but others do not, e.g.TextInput
.The
deprecateFieldOnObject
function added in #9008 by @tay1orjones relies ondisplayName
to be set in order to produce a useful message. If a Carbon user currently uses the now-deprecated formTextInput.PasswordInput
, they receive the following warning message: "Warning: The PasswordInput field has been deprecated on the undefined object. Please import and use the field directly." The word "undefined" appears in that message becauseTextInput
does not currently havedisplayName
set on it.Yes, quite a lot of them. The following components DO have a
displayName
set currently. All the other components would be candidates to havedisplayName
set on them.Only two components currently use
deprecateFieldOnObject
, and they are:displayName
setAt least
TextInput
should have adisplayName
set so that the deprecation message is shown correctly. Some thought should then be given as to whether some other, or maybe all other, components should havedisplayName
set systematically.n/a
10.41.0