我需要displayName一个 React 组件的属性。如果没有,React DevTools 会显示Anonymous. 我尝试为exportand单独一行const Titlebar = function(props){...},但没有运气。DevTools 可以不直接读取函数名displayName吗?
export function Titlebar (props: TitlebarProps): React.ReactElement {
return (
<h1 className={styles.titlebar}>
<a href='/'>{props.title}</a>
</h1>
)
}
Titlebar.displayName = 'Titlebar'