S
SolidJS7mo ago
Liquido

How can I use SolidJS ref with typescript?

I want to create a ref to a canvas element:
export const Canvas = () => {
let ref: HTMLCanvasElement;

return <canvas ref={ref} width={500} height={500}></canvas>;
};
export const Canvas = () => {
let ref: HTMLCanvasElement;

return <canvas ref={ref} width={500} height={500}></canvas>;
};
But I keep getting TS error that "Variable ref is being used without being assigned." What's the correct way to use refs with Typescript?
1 Reply
lxsmnsyc
lxsmnsyc7mo ago
let ref: HTMLCanvasElement! or just use signals