Use of helper in Aura
- johnsontitus
- May 14, 2020
- 1 min read
Put functions that you want to reuse in the component’s helper. Helper functions also enable specialization of tasks, such as processing data and queueing server-side actions.
Eg:
/* helper */ ({ updateItem : function(component, item, callback) { // Update the items via a server-side action i.e calling apex method - saveItem var action = component.get("c.saveItem"); action.setParams({"item" : item}); // Set any optional callback and enqueue the action if (callback) { action.setCallback(this, callback); } $A.enqueueAction(action); } })
A helper function can be called from any JavaScript code in a component’s bundle, such as from a client-side controller or renderer.
Eg:
/* controller */ ({ newItemEvent: function(component, event, helper) {
//calling the helper function helper.updateItem(component, event.getParam("item")); } })


Comments