[typescript] Define components as ComponentClass, not ComponentType
See original GitHub issueSee e.g. Button: https://github.com/mui-org/material-ui/blob/b29f1cbec31548291a75959d3627473569343eb4/src/Button/Button.d.ts#L36.
ComponentClass supports ref=
whereas ComponentType doesn’t (because the component may be a stateless functional component). So any attempt to use ref=
results in a Typescript compile error.
ref’s are often used to find the anchor element for popovers and similar.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
[typescript] Define components as ComponentClass, not ...
ComponentClass supports ref= whereas ComponentType doesn't (because the component may be a stateless functional component). So any attempt to ...
Read more >What is the Typescript type to accept any kind of React ...
React.ComponentType<P> is the type for either a class component ( React.ComponentClass<P> ) or function component ( React.
Read more >Class Components - React TypeScript Cheatsheets
Within TypeScript, React.Component is a generic type (aka React.Component), so you want to provide it with (optional) prop and state type parameters:
Read more >How to Statically Type React Components with TypeScript
In this guide, you will learn how to statically type React.js components using the compile-to-JavaScript language, TypeScript.
Read more >React Higher-Order Components in TypeScript - Medium
Note that the examples in this article do not demonstrate best practices, ... Here we are defining a component to return from the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For most Material UI components, the argument to a
ref={...}
callback would be thewithStyles
HOC instance… probably not what you want. It seems like a leakage of implementation details to expose that, hence why we useComponentType
everywhere, and instead expose targetedfooRef
props where appropriate.Ready to close, by me.