How to use
; Component { superprops; ; } { } { return <button onClick=thisonClick>Click me</button> }
bindToClass
will bind method onClick
to the current components scope.
You could do it also like:
{ superprops; thisonClick = thisonClick; }
Though in comparison to the usual bind, this bindToClass
will warn you whenever you forgot to bind.
Which means, that this code, will also work, keeping your app stable.
; Component { superprops; ; } { } { } { return <button onKeyDown=thisonKeyDown onClick=thisonClick>Click me</button> }
Benefits
- All methods are bound even the onse you haven't included
- Helps to prevent wrong
this
scope in event handlers - Gives warnings, so that it can be fixed later without stopping the app from working
- Helps to prevent wrong
- Gives error if methodName doesn't exists at the moment of instance creation
- Error happens before the real event