Skip to main content
New tool CRON Expression Builder — preview next run times before you schedule Apex. Open the builder →
Diagram illustrating the key differences between LWC decorators: @track, @api, and @wire.
LWC

Difference between @Track, @api and @wire LWC decorators

Learn the differences between track, wire, and api decorators in Salesforce LWC, and how to choose the right decorator for your use case.

The short answer

In Lightning Web Components (LWC), the wire decorator retrieves data from server-side controllers or Apex methods. The returned data lands in a component property, which makes the component rerender with the new data.

Key takeaways Use @wire to pull data from a server-side controller or Apex method straight into a component property. Use @track to watch property changes inside a component and trigger a rerender. Use @api to expose a property or method so a parent component can reach it.

In Salesforce Lightning Web Components (LWC), the wire decorator pulls data from server-side controllers or Apex methods straight into a component property. When the method returns data, the component rerenders on its own to show the new values. It is one of the three core decorators in LWC, alongside track and api.

Difference between @Track, @api and @wire LWC decorators

The track decorator

The track decorator watches a property's value inside the component. Whenever the value of a tracked property changes, the component rerenders and shows the updated value.


import { LightningElement, track } from 'lwc';

export default class ExampleComponent extends LightningElement {
  @track greeting = 'Hello';

  handleChange(event) {
    this.greeting = event.target.value;
  }
}
    

The wire decorator

The wire decorator fetches data from server-side controllers or Apex methods. The data the method returns lands in the component's property, and the component rerenders with it.


import { LightningElement, wire } from 'lwc';
import getContacts from '@salesforce/apex/ContactController.getContacts';

export default class ContactList extends LightningElement {
  @wire(getContacts) contacts;
}
    

The api decorator

The api decorator exposes a component's property or method to the parent component, so the parent can read that property or call that method.


import { LightningElement, api } from 'lwc';

export default class ExampleComponent extends LightningElement {
  @api message = 'Hello World';
}
    

Summary

So: track watches a property's value inside the component, wire retrieves data from server-side controllers or Apex methods, and api exposes a component's property or method to the parent component. Between them they cover what a component property usually has to do: react to its own changes, receive server data, and be reachable from the parent.

Frequently asked questions

What is the difference between @track, @api, and @wire in LWC?

In LWC, `@wire` retrieves data from server-side controllers or Apex methods, `@track` monitors internal component property changes to trigger rerendering, and `@api` exposes properties or methods to parent components.

When should you use the @wire decorator in LWC?

Use `@wire` to retrieve data from server-side controllers or Apex methods directly into a component property, which automatically rerenders the component when new values return.

When should you use the @api decorator in LWC?

Use `@api` to expose a component's property or method so that a parent component can access and interact with it.

When should you use the @track decorator in LWC?

Use `@track` to track changes to a property's value within a component and ensure the component rerenders to display the updated value.

Newsletter

One email every Tuesday

New guides, tool updates, and the release-note changes that break things.

No spam. Unsubscribe in one click.

Comments

Loading comments...

Leave a Comment