I'm trying to render a dashboard using ResponsiveReactGridLayout
and my code in the functional component is as follows:
const Home = () => {
const [coins, setCoins] = useState(latestCoins);
const [coin, setCoin] = useState(curCoin);
const canvasRef = useRef(null);
useEffect(() => {
getCoins().then((data) => setCoins(data));
}, []);
return (
<ResponsiveReactGridLayout
onResize={(e) => console.log(e)}
className="layout"
layouts={layouts}
rowHeight={100}
breakpoints={{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }}
cols={{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }}
>
<div key="candlestick" className="home-card" ref={canvasRef}>
{console.log(canvasRef)}
//Trying to use canvasRef.current.width and height but getting an error: Property 'width' does not exist on type 'never'
<Candlestick coin={coin} width={600} height={400} />
</div>
</ResponsiveReactGridLayout>
);
};
My Candlestick component does return a ChartCanvas object from react-stockcharts
, which needs a width and height (without which it does not take up the entire space of the div)
How can I get the height and width from the div?
I've tried using the useRef()
hook, but it always seems to have current as null.
Could I get some help?