Events Anti-Patterns

These are some anti-patterns that you should avoid when using events.

Don't Fire an Event in a Renderer

Firing an event in a renderer can cause an infinite rendering loop.

Don’t do this!

afterRender: function(cmp, helper) {
    this.superAfterRender();
    $A.get("e.myns:mycmp").fire();
}

Instead, use the init hook to run a controller action after component construction but before rendering. Add this code to your component:

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

For more details, see .Invoking Actions on Component Initialization.

Don’t Use onclick and ontouchend Events

You can’t use different actions for onclick and ontouchend events in a component. The framework translates touch-tap events into clicks and activates any onclick handlers that are present.