Preact: Question: `on*` props callbacks

Created on 16 Jan 2018  路  4Comments  路  Source: preactjs/preact

Is there a way to pass a prop called with the prefix on without it being registered as an event handler?

I might been doing it wrong all this time but I normally pass functions as props and call them onSomethingHappened.

Most helpful comment

setAccessor is called by diffAttributes https://github.com/developit/preact/blob/66d74c5d210ee72e41732e6aa5efb0e23d0c09ba/src/vdom/diff.js#L307 which is called by idiff https://github.com/developit/preact/blob/66d74c5d210ee72e41732e6aa5efb0e23d0c09ba/src/vdom/diff.js#L148.
But in case of components idiff returns early https://github.com/developit/preact/blob/66d74c5d210ee72e41732e6aa5efb0e23d0c09ba/src/vdom/diff.js#L100 bevor any dom diffing code is executed.
So setAccessor is only executed for vdom nodes that represent a real dom node and not for components.

All 4 comments

On components and functional components props starting with on are passed as normal props.
No need to change anything.
Here an example showing preacts behavior.

Thanks @Kanaye! That example was just what I needed.

I guess I don't understand this part of the code then https://github.com/developit/preact/blob/66d74c5d210ee72e41732e6aa5efb0e23d0c09ba/src/dom/index.js#L65 not sure when this is running.

setAccessor is called by diffAttributes https://github.com/developit/preact/blob/66d74c5d210ee72e41732e6aa5efb0e23d0c09ba/src/vdom/diff.js#L307 which is called by idiff https://github.com/developit/preact/blob/66d74c5d210ee72e41732e6aa5efb0e23d0c09ba/src/vdom/diff.js#L148.
But in case of components idiff returns early https://github.com/developit/preact/blob/66d74c5d210ee72e41732e6aa5efb0e23d0c09ba/src/vdom/diff.js#L100 bevor any dom diffing code is executed.
So setAccessor is only executed for vdom nodes that represent a real dom node and not for components.

鉂わ笍 It finally makes sense (to me)! Thank you so much @Kanaye

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jasongerbes picture jasongerbes  路  3Comments

simonjoom picture simonjoom  路  3Comments

KnisterPeter picture KnisterPeter  路  3Comments

matuscongrady picture matuscongrady  路  3Comments

matthewmueller picture matthewmueller  路  3Comments