I'm creating a speedometer in reactJS and using a little vanilla syntax, however canvas is returning null. If I run
const canvas = document.getElementById('dial__container');
in the console the div pops right up.
Is this merely a timing issue where the canvas hasn't yet rendered or some weird React behavior?
import React from 'react';
const canvas = document.getElementById('dial__container');
const ctx = canvas.getContext('2d');
const radius = canvas.height / 2;
const Speedometer = (props: any) => {
console.log(canvas); // null
return (
<div className="dial__wrapper">
<canvas id="dial__container" width="150" height="150" />
</div>
);
};
export default Speedometer;