Access component variable in Callback function Salesforce Lightning component

You might have face issue somewhere in component where you are triggering some JavaScript callback function, and in callback function you want to perform some logic on component variable but you got stuck in accessing component.

Becuase modifiing component outside the normal rerending lifecycle is not allowed. 

for example you using setTimeout().

To resolve this issue wrap your callback function into $A.getCallback(), which modifies a component outside the normal rerendering lifecycle.


window.setTimeout(
    $A.getCallback(function() {
        component.set("v.attribute", "attributevalue");
    })
);

 

Hope this will help! Enjoy Coding!!!

For more information visit here.

No comments:

Post a Comment