Friday, May 6, 2022

Data Binding

 Data binding is a technique, where the data stays in sync between the component and the view.

Whenever the user updates the data in the view, LWC updates the component. When the component gets new data, the LWC updates the view.

Data Binding is of  two  types:

One-way Data Binding:

One-way data binding is a situation where information flows in only one direction in our case from the controller to the template(HTML).

Two-Way Binding:

Two-way data binding in LWC will help users to exchange data from the controller to the template and form template to the controller.

 It will help users to establish communication bi-directionally.

  • The Lightning Web Components programming model has given us some decorators that add functionality to property or function.
  • @track is the decorator that helps us to track a private property's value and re-render a component when it changes.
  • Tracked properties are also called private reactive properties.
  • @track helps us to achieve two-way data binding

Track a property only if you want the component to re-render when the property's value changes.

Note: Don't track every private property.

 

No comments:

Post a Comment

ES12 new Features