@wire decorator. It includes debouncing to optimize performance when handling user input.
Implementation
Key Features
Reactive Parameters
Use the$ prefix to make parameters reactive:
searchKey changes, the wire adapter automatically calls the Apex method with the new value.
Parameter Syntax
The second argument to@wire is an object mapping Apex parameter names to component properties:
Debouncing
Implement debouncing to reduce unnecessary Apex calls:Search Pattern
The Apex method uses SOQL’s LIKE operator for partial matching:Parameters
Component Properties
| Property | Type | Description |
|---|---|---|
searchKey | String | The search term for filtering contacts |
contacts | Object | Wire adapter result with data and error |
delayTimeout | Number | Timeout ID for debouncing |
Apex Method Parameters
| Parameter | Type | Description |
|---|---|---|
searchKey | String | Search term to filter contacts by name |
Performance Optimization
Why Debounce?
Without debouncing, typing “John” would trigger 4 Apex calls:- “J”
- “Jo”
- “Joh”
- “John”
Debounce Configuration
- Lower (100-200ms): More responsive, more server calls
- Higher (500-1000ms): Fewer server calls, less responsive
Error Handling
Errors are automatically handled through the wire adapter:When to Use
Use this pattern when:- You need to pass parameters to an Apex method
- Parameters change based on user input
- You want automatic re-execution when parameters change
- You need search or filter functionality
Best Practices
- Always use debouncing for text input
- Use the
$prefix for reactive parameters - Set appropriate LIMIT in SOQL queries
- Include WITH USER_MODE for security
- Clear timeout on component destroy if needed
