[英]How to display logged user name in a React application
I am trying to display logged in username
and user profile
in my React app using TypeScript:我正在尝试使用 TypeScript 在我的 React 应用程序中显示登录的
username
和user profile
:
{window.user_image ? (
<img src={window.user_image}/>
):(
<UserAvatar/>
)}
<h3>{window.display_name}</h3>
But I am getting the following errors:但我收到以下错误:
Property 'user_image' does not exist on type 'Window & typeof globalThis
属性 'user_image' 在类型 'Window & typeof globalThis 上不存在
Property 'display_name' does not exist on type 'Window & typeof globalThis
属性 'display_name' 在类型 'Window & typeof globalThis 上不存在
How can I display the logged in user name in a TypeScript file, eg info.tsx
如何在 TypeScript 文件中显示登录用户名,例如
info.tsx
{window.["user_image"] ? (
<img src={window.["user_image"]}/>
):(
<UserAvatar/>
)}
<h3>{window.["user_image"]}</h3>
This solved my problem这解决了我的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.