I'm trying to implement a refresh button in one of my components. I'm using the @wire decorator with getListUi to get a list of records for each of which I'm rendering a component. The @wire method calls when the component is mounted, but I also want to call it when I hit a reload button in the UI. Any idea how to achieve this? Here is what I have so far: (Not working)
import { LightningElement, track, wire } from 'lwc';
import { getListUi } from 'lightning/uiListApi';
import CONTENT_OBJECT from '@salesforce/schema/Content_Item__c';
export default class DayCards extends LightningElement {
@track contentItems;
@track error;
@wire(getListUi, {objectApiName: CONTENT_OBJECT, listViewId: '00B9A000001AitaUAC' })
wiredContent({error, data}) {
if (data) {
this.contentItems = data.records.records;
console.log('data: ', data.records.records);
} else if (error) {
console.log('error: ', error);
}
}
reloadItems(event) {
console.log('refreshing');
this.wiredContent(); // I want to call the @wire method again here
}
}
<template>
<div class="day-cards slds-p-around_medium slds-box slds-box_small">
<div if:true={error}>{error}</div>
<div class="refresh-button">
<lightning-button-icon icon-name="action:refresh" variant="bare" alternative-text="Refresh" icon-class="slds-m-around_medium"
onclick={reloadItems}></lightning-button-icon>
</div>
<template for:each={contentItems} for:item="item">
<c-day-card key={item.fields.Id.value} date={item.fields.Date__c.value} description={item.fields.Description__c.value}
link-url={item.fields.Redirect_URL__c.value}></c-day-card>
</template>
</div>
</template>