Why respond to server side handlers?

I have a React Server Side processed side with a tag img. I want to add an event listener onloadto the image tag and make the component as shown below:

render () {
  return (
    <img onLoad={() => { console.log('Image loaded'); }} src='/abc.jpg'/>
  )
}

Ideally, a React renderToStringmethod should generate an HTML template, as shown below:

<img onload='function () { console.log('Image loaded'); }' src='/abc.jpg' />

but this is not so. What am I missing? I checked there was a similar problem here , but without a solution

+4
source share
1 answer

React does not use the built-in event handlers in dom / html. Listeners are added with JavaScript when your application loads on the client.

, .

, :

var a = 1;
<div onClick={() => console.log(a)}</div>

, React inline.

+2

Source: https://habr.com/ru/post/1673471/


All Articles