8

I'm creating an lwc, and I've been using an imperative call to get data, where it's easy to include setting a property isLoading before the call, so that a spinner shows while it's getting the data.

fetchResponses(){
    this.isLoading = true;
    getResponseMap ({
        campaignId: this.selectedCampaign,
        ... etc.

I'm cleaning up my code and I'd like to convert this imperative call to an @wire method, but I can't figure out where to put the isLoading line. If I put it after the call, I'm thinking it won't activate the spinner until the server has returned the result. Right?

Do I have to set isLoading in outside this method, like in a connectedCallback handler? That kills what I'm trying to do to clean up the code.

8

I recommend wiring to a property and using a getter to determine if no error or data has been provisioned.

@wire(getResponseMap, {...}) wiredProperty;

get isLoading() {
  return !this.wiredProperty.data && !this.wiredProperty.error;
}
0

You can put it in the setter function of the reactive variable bound to the wire.

You'll have to excuse the brevity, I'm on mobile and will edit my answer later with an example if you need clarity.

1
  • Hi, can you please update your answer Jan 5 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.