Here’s my little tip, how to add multiple listeners to a functional component.
// in render functionconstfunctionNames=Object.keys(listeners);constcombinedFunctions=ctx=>functionNames.forEach(fn=>listeners[fn](ctx));constbutton=h('button',{...functionNames.length&&{on:{click:combinedFunctions}}},content);returnbutton;
Really great tips! Thanks for sharing!
Here’s my little tip, how to add multiple listeners to a functional component.
Thanks for the comment Andrei. Is that equal to:
?
why is that
listeners
instead of$listeners
?in functional components, it's
listeners
. DocsDoesn’t seem to work. 🤔
What doesn't seem to work?
Your snippet. There’s a likelihood of me doing something wrong though. I’m rendering my component using a render function.
Since we are talking about functional components the full code snippet should be:
I’ll give it another try tomorrow and I’ll let you know how it went!