Skip to main content
Parent-child communication in Lightning Web Components is achieved through public properties decorated with @api. This enables a unidirectional data flow where parents control the state and behavior of their children.

The @api Decorator

The @api decorator makes a property or method public, allowing parent components to access it. Properties marked with @api are reactive, meaning changes automatically trigger a re-render of the component.

Importing @api

Public Properties

Public properties allow parent components to pass data to child components.

Child Component Definition

contactTile.js
contactTile.html

Parent Component Usage

compositionBasics.js
compositionBasics.html

Multiple Public Properties

A child component can expose multiple public properties to accept different types of data.

Example: Multiple Properties

child.js
child.html
Parent usage:
Property names in HTML use kebab-case (first-name), but the corresponding JavaScript property uses camelCase (firstName)

Property Binding

You can bind parent component properties to child component properties using curly braces {}.

Static Values

Dynamic Values

Complex Objects

You can pass entire objects, not just primitive values:

Best Practices

1

Use descriptive property names

Choose clear, self-documenting names for your public properties
2

Validate input data

Check for null or undefined values in your child component
3

Keep components focused

Each component should have a single, well-defined responsibility
4

Document public APIs

Use JSDoc comments to document what each public property expects

Data Flow Rules

Data flows down from parent to child. Child components should not modify properties received from parents. This ensures a predictable, unidirectional data flow.
  • Parent controls the data: The parent component owns and manages the state
  • Child receives the data: The child component receives data through @api properties
  • Child displays the data: The child component renders the data but doesn’t modify it
  • Child communicates changes: If the child needs to trigger changes, it dispatches events to the parent

Common Patterns

Passing Primitive Values

Passing Objects

Passing Arrays

See the Nesting Patterns guide for examples of passing arrays and iterating over child components.

Next Steps

Nesting Patterns

Learn about iterating over arrays to create multiple child instances

Events

Discover how child components communicate back to parents