I am trying to build a simple component in Svelte. Image component with fallback in case the src is invalid. This is my code and it doesn't work. I've tried many variations (on:error instead of onError, listen to error on mount which was sometimes too late) but none worked.
Any idea what is the right approach?
<script> import TCFavIcon from '@src/common/icons/TCFavIcon.png'; export let src = TCFavIcon; export let alt = undefined; function handleError() { console.log('error'); // This never happen even when src is invalid src = TCFavIcon; } </script> <style> </style> <img onError={handleError} {alt} {src} />