How to check Component Validity in Salesforce lightning?

If you navigate elsewhere in the UI while the asynchronous code is executing, the framework un renders and destroys the component that made the asynchronous request. You can still have a reference to that component, but it is no longer valid.

The cmp.isValid() call returns false for an invalid component.

If you call cmp.get() on an invalid component, cmp.get() returns null.

If you call cmp.set() on an invalid component, nothing happens and no error occurs. It’s essentially a no op.

In many scenarios, the cmp.isValid() call isn’t necessary because a null check on a value retrieved from cmp.get() is sufficient. The main reason to call cmp.isValid() is if you’re making multiple calls against the component and you want to avoid a null check for each result.

No comments:

Post a Comment