I am trying to clarify the pros and cons of having a new function declaration in a reaction rendering method.
Consider a rendering method, for example:
render () {
return (<SomeComponent somePropWithoutEventBind={() => console.log('not so dangerous?')} />)
}
In the above example, it somePropWithoutEventBinddoes not bind to the DOM event: the reaction will check for prop changes, and every time the render is called this, this parameter has changed - since this is a new function, therefore it never coincides with the previous one, it is expensive, but nothing grandiose.
Now in this case
render () {
return (<input onChange={() => console.log('dangerous?')} />)
}
onChange prop is binding to the DOM (something like addEventListener) so that every rendering should again removeEventListenerand addEventListener? Is this the main reason for refusing to declare functions inside the rendering method?
, , , .