1

I need a displayName property for a React component. If not, React DevTools shows Anonymous. I attempted a separate line for export and const Titlebar = function(props){...}, no luck. Can DevTools read the function name directly without displayName?

export function Titlebar (props: TitlebarProps): React.ReactElement {
  return (
    <h1 className={styles.titlebar}>
      <a href='/'>{props.title}</a>
    </h1>
  )
}

Titlebar.displayName = 'Titlebar'
steve76
  • 302
  • 2
  • 9
  • It reads it directly, depends on how you render `TitleBar`, for example `React.memo(Titlebar)` displayName won't show `Titlebar` – Dennis Vash Jun 14 '20 at 14:29
  • Nothing fancy: ReactDOM.render( Diez Element -> div -> Titlebar, document.getElementById('root') ) – steve76 Jun 14 '20 at 14:36

0 Answers0