How can I prevent canvasRef.current from being undefined here? It seems the modal component from material ui is causing problems with the canvas ref. How can I prevent this