Add option to pass functions as values for TSX HTML element attributes:
const html = <button onclick={ ( {alert} )=>{ alert("clicked!") } }></button>;
The functions should be stringified with fn.toString() - but only the body of the function should be passed to the resulting HTML. The ( {alert} ) => {) and the closing } should be omitted. This removal should work for:
- anonymous functions - function({alert}){}
- named functions - function test({alert}){}
- arrow functions - ()=>console.log("hehe")
- arrow functions with brackets - ()=>{console.log("hehe")}
Typescript should be informed about the types for the argument to that function - it should be an object that contains the global DOM variables, like document, alert, etc.