Search code examples
reactjstypescriptreact-tsx

Property 'onload' does not exist on type <ImgHTMLAttributes>


There is my code to use image tag in typescript

<img
  className="mediaImg"
  src={imageUrl}
  onload={() => console.log('dffffffffffffffffffffffff')}
  style={{ ...theme.messages.mediaImg }}
/>

When I use onload attribute there I get the error

Property 'onload' does not exist on type 'DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>'

Any help would be appreciated!!! Thank you


Solution

  • You have to call onLoad instead onload.

    <img
     className="mediaImg"
     src={imageUrl}
     onLoad={() => console.log('dffffffffffffffffffffffff')}
     style={{ ...theme.messages.mediaImg }}
    />