Leanote's Blog
I love Leanote!
Toggle navigation
Leanote's Blog
Home
Chrome
Git
Linux
Windows
Others
工具大全
VsCode
Expo
Html
JavaScript
Npm
Node
Mock
React-Native
React
TypeScript
小程序
插件
正则
Dva
Ant-Design-React
Umi
Vue
Vux
Ant-Design-Vue
Http
Java
flutter
开发小工具
About Me
Archives
Tags
使用infer推断出React.Ref<T>里的T类型
2023-06-09 17:41:49
11
0
0
admin
```tsx type InputRefType<T> = T extends React.Ref<infer ElementType> ? ElementType : never; const inputRef = useRef<HTMLInputElement>(null) type MyInputRefType = InputRefType<typeof inputRef> const a: React.RefObject<MyInputRefType> = inputRef a.current?.focus() ```
Pre:
react forwardRef导致泛型丢失
Next:
React.Ref,React.RefObject 和 React.MutableRefObject区别
0
likes
11
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.