Property 'ref' does not exist on type 'IntrinsicAttributes & IconButtonProps & { children?: ReactNode; }'
This is the case for IconButton, but might be the case for others as well (didn't test any others).
The ref property should be available for any react component.
It is not, making TS complain with a 'Property 'ref' does not exist on type 'IntrinsicAttributes & IconButtonProps & { children?: ReactNode; }' when trying to add it.
Create a tsx file that uses the following:
<IconButton
ref={node => { console.log(node); }}
>
</IconButton>
| Tech | Version |
|--------------|---------|
| Material-UI | latest beta |
| React | 16 |
| browser | Chrome 62 |
| ts| 2.6.1 |
This is because IconButton is declared as a React.ComponentType instead of a React.ComponentClass; we're purposely abstracting away whether IconButton even has an instance associated with it. It happens that it does, but it's probably not what you want; its instance is a result of the withStyles HOC. Are you sure you don't want either the rootRef or buttonRef props?
Actually I wanted buttonRef as target anchor element for a popover :) Thanks
is it fixed? why close it? because i still get the warning.
constructor(props) {
super(props)
this.myRef = React.createRef()
}
i get the warning: [at-loader] property "myRef" does not exist on type ...
Most helpful comment
This is because
IconButtonis declared as aReact.ComponentTypeinstead of aReact.ComponentClass; we're purposely abstracting away whetherIconButtoneven has an instance associated with it. It happens that it does, but it's probably not what you want; its instance is a result of thewithStylesHOC. Are you sure you don't want either therootReforbuttonRefprops?