0

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

Dark Knight
  • 995
  • 4
  • 22
  • 48

1 Answers1

2

You have to call onLoad instead onload.

<img
 className="mediaImg"
 src={imageUrl}
 onLoad={() => console.log('dffffffffffffffffffffffff')}
 style={{ ...theme.messages.mediaImg }}
/>
Amruth
  • 5,792
  • 2
  • 28
  • 41
  • 1
    Then I get this `Type 'void' is not assignable to type '((event: SyntheticEvent) => void) | undefined'.` – Dark Knight Sep 21 '18 at 07:14
  • am not getting any errors or warnings, may be its problem with your `style={{ ...theme.messages.mediaImg }}` – Amruth Sep 21 '18 at 07:17
  • 1
    I was not returning anything in the onLoad function and I integrated eslint in my code. – Dark Knight Sep 21 '18 at 07:34
  • Hi one more question how do I pass prop from one component to another in typescript? – Dark Knight Sep 21 '18 at 07:46
  • google it, you will get many references. check here -> https://stackoverflow.com/questions/22639534/pass-props-to-parent-component-in-react-js – Amruth Sep 21 '18 at 08:32