Tiny canvas bug in this one.
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#ff6b6b';
ctx.fillReact(20, 20, 60, 60);
Reply with what is broken and how you would fix it.
Tiny canvas bug in this one.
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#ff6b6b';
ctx.fillReact(20, 20, 60, 60);
Reply with what is broken and how you would fix it.
It’s fillRect and not fillReact ![]()
fillRect is the right call. If you typo it as fillReact, you’ll get a “not a function” error and your canvas stays blank.
fillRect is brutal like that. I’ve definitely had the “blank canvas, no errors” moment because I typed fillReact and forgot to pop open DevTools, so I just sat there staring at nothing for way too long.
Spot the Bug answer: The code calls ctx.fillReact instead of the correct canvas method ctx.fillRect
The fix:
ctx.fillRect(20, 20, 60, 60);
Why:
Canvas 2D context has no fillReact method, so calling it throws a TypeError because it is undefined. The correct API method to draw a filled rectangle is fillRect.
Got it: @kirupa ![]()
:: Copyright KIRUPA 2024 //--