Introduction

The main concept included in this recipe is how to send an event to other components so they can refresh their contents without reloading the whole page.

<aside> πŸ’‘ If you are not familiar with the RefreshView API, review this section before digging into this LWC RefreshView API.

</aside>

<aside> πŸ“‚ Find this LWC in this folder: force-app/main/default/lwc/dispatchRefreshEvent.

</aside>

Template file

The template uses a standard lightning-record-edit-form LDS component to allow the user to create a new account.

<aside> ☝ Review how a here lightning-record-edit-form is used here:

LWC recordEditFormStaticContact and recordEditFormDynamicContact

</aside>

Javascript file

The handler associated to saving the account is named handleSuccess.

In this handler, the most important and straightforward code is:

//Dispatch the refresh event
this.dispatchEvent(new RefreshEvent());

With this single line, the account standard LDS list view will receive the Refresh View signal and will refresh the data inside without requiring to reload the whole page.

If a custom LWC was in the same page, a registration for this event might be necessary to receive this event.

Next recipe

LWC LightDomQuery

Feedback?

Did you find an issue/mistake? You don’t like something? Do you have external content that I should link to improve the learning process? Did you find it helpful? Any of those are super valuable to me. So, please write me at [email protected], and promise to answer.

<aside> ↗️ Jump to the main page: The LWC Recipes Cookbook

</aside>