TypeScript: Errors on react-konva refs
See original GitHub issueWhen I try to simulate the hover animation example from Expand Images on Hover on my project with TypeScript with regards to React refs, I have stumbled several errors. Below is the code example that I have the errors:
import { Circle, Layer, Group, Text } from "react-konva";
interface AProps {
...
}
export default class A extends React.Component<AProps, {}> {
private layer: React.RefObject<typeof Layer>;
constructor(props: AProps) {
super(props);
this.layer = React.createRef<typeof Layer>();
}
handleExpand = e => {
const shape = e.target;
document.body.style.cursor = "pointer";
shape.scaleX(1.5);
shape.scaleY(1.5);
this.layer.current!.draw();
};
handleRestore = e => {
const shape = e.target;
document.body.style.cursor = "default";
shape.scaleX(1);
shape.scaleY(1);
this.layer.current!.draw();
};
render() {
const { width, color } = this.props;
return (
<Layer ref={this.layer}>
<Circle
x={x}
y={y}
radius={width / 2 - 10}
fill={color}
stroke={'#000000'}
strokeWidth={2}
/>
</Layer>
);
}
}
The errors are as following:
this.layer.current!.draw();
- Property ‘draw’ does not exist on type ‘KonvaContainerComponent<Layer<Node>, LayerConfig>’.ref={this.layer}
- Type ‘RefObject<KonvaContainerComponent<Layer<Node>, LayerConfig>>’ is not assignable to type ‘string | ((instance: Layer<Node> | null) => void) | RefObject<Layer<Node>> | null | undefined’. Type ‘RefObject<KonvaContainerComponent<Layer<Node>, LayerConfig>>’ is not assignable to type ‘RefObject<Layer<Node>>’. Type ‘KonvaContainerComponent<Layer<Node>, LayerConfig>’ is missing the following properties from type ‘Layer<Node>’: getIntersection, enableHitGraph, disableHitGraph, clearBeforeDraw, and 128 more.
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
React Konva share ref between sibling components throws error
I get 2 TypeScript errors in store/index.ts : TS2531: Object is possibly 'null'. on stageRef when I try to access stageRef.current ...
Read more >How to access Konva nodes from react-konva?
There are two ways to access Konva nodes/shapes from react-konva . Using the refs API. You can use the refs API to get...
Read more >react-konva + ts - CodeSandbox
TemplateReact Typescript; Environmentcreate-react-app. Files. public. src. App.tsx. index.tsx. styles.css. package.json. tsconfig.json. Dependencies. konva.
Read more >React Konva share ref between sibling components throws error
types/index.ts. export interface IFrameItStore { downloadImage(stageRef: React.ForwardedRef<StageType>): void }. I get 2 TypeScript errors in ...
Read more >Guide to canvas manipulation with React Konva
React Konva allows you to draw, transform, and drag shapes around the canvas much more easily than with vanilla JavaScript.
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
Can you make a small demo repo? I just tried this:
Works ok for me.
You should import the Layer for the ref from Konva not from react-konva. that is