# What is the role of the dollar sign prefix ($) when passing reactive parameters to wire adapters?

**Topic:** LWC · **Difficulty:** Medium · **Tags:** LWC, Wire Service, Reactivity

Read it on the site: https://www.forcechallenges.com/interview-questions/what-is-the-role-of-the-dollar-sign-prefix-when-passing-reactive-parameters-to-wire-adapters

## Answer

**Basics:** `@wire` configuration is an object. A plain value (`fields: [NAME]`) is fixed at setup. A string beginning with `$` is a reference to a property on the component, which makes the wire reactive: change the property and the wire service provisions new data to the wired property or function.

**How it works:** Example `@wire(getRecord, { recordId: '$recordId', fields: FIELDS })`. When `recordId` is set or changes, the adapter is called with the new value and its result goes into `data`/`error`. If any reactive value is `undefined`, LDS adapters generally do not fire until it is defined, which is why wires wait for `@api recordId` to arrive. The `$` is only for the config object, never in the component code or template.

**Advanced / deep dive:** Reactivity is triggered by reassignment of the referenced property; mutating a nested field of an object does not trigger it, so assign a new object. The `$` references a property on `this` (top-level), so compute dependent values into a property or getter rather than deep paths. For Apex wires, `@wire(getData, { accountId: '$recordId', filter: '$filter' })` re-invokes the cacheable method on any change, so debounce text-input driven properties (for example 300 ms) to avoid a request per keystroke. Wire methods must be `cacheable=true`, so they cannot perform DML; for actions use imperative calls. To control when a wire runs, set the reactive property to `undefined` until ready (verify per adapter, as behavior with undefined can vary for Apex). Wired function form `@wire(getRecord, {...}) handler({ data, error })` is useful for multiple derived values and for testing.

**Code / config example:**
```javascript
import { LightningElement, wire } from 'lwc';
import searchAccounts from '@salesforce/apex/AccountCtrl.search';

export default class Search extends LightningElement {
    term = '';
    _t;
    @wire(searchAccounts, { term: '$term' }) accounts;

    handleInput(e) {
        const v = e.target.value;
        clearTimeout(this._t);
        this._t = setTimeout(() => { this.term = v; }, 300); // debounce
    }
}
```

**Hidden gotchas & must-remember points:**
- Forgetting `$` makes the parameter the literal string `'recordId'`.
- Mutating an object in place does not re-trigger the wire; reassign.
- Wired Apex methods must be `@AuraEnabled(cacheable=true)`.
- Each reactive change causes a new request or cache lookup; debounce typed input.
- You cannot use `$` for expressions or method calls.
- Wired properties are read-only; copy before modifying.

**Best practice:** Use reactive wires for read-only data driven by a few simple properties, and debounce any user-typed values.

---
Source: ForceChallenges · last updated 2026-11-02
