0

I'm getting data from server using @wire when the @api property changed. How to show spinner whenever getting data from server?

@api classId;

@tract isLoading = true;

@wire(wiredMethod, { classId: '$classId' })
wiredProperty({ data, error }) {
    this.isLoadig = false;
});

First time it is working fine on second time it is not showing spinner.

If I'm setter getter for classId it shows [Maximum call stack size exceeded] this error.

1 Answer 1

1

I do not see anything in your code which would ever set isLoading back to true. Perhaps something like this would work:

_privateClassId;
@track _isLoading = false;
@wire(wiredMethod, { classId: '$classId' })
wiredProperty({ data, error }) {
    this._isLoading = false;
});

set classId(value) {
    if (value) {
        _isLoading = true;
        this._privateClassId = value;
    }
}

@api
get classId() {
    return this._privateClassId;
}
1
  • May i know why I can't directly use @api property in @wire? Commented Apr 6, 2020 at 3:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .