What does the Lightning component method component.isValid() do?

I have read in the Lightning Component Developer guide that it is recommended to use the component.isValid() check any time you are referencing a component in asynchronous code such as in the helper controller when handling the response from the server-side controller. I have not been able to find in the documentation exactly what this function is doing. Could someone explain what this isValid() function is doing?

Thank you for any information you can provide.

This is an example from the developer guide of how it is used:

  getExpenses: function (component) {
    var action = component.get("c.getExpenses");
    var self = this;
    action.setCallback(this, function(response) {
       var state = response.getState();
       if (***component.isValid()*** && state === "SUCCESS") {
           component.set("v.expenses", response.getReturnValue());


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If in the time it took to get the expenses from the server, you switched screens and have unrendered the component that was making the request, the component would have been destroyed.

In this case, you’ll still have a reference to that component, but it will no longer be valid.

Simply, checks if the component has been destroyed or not.

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x